Error Handling
The Javascript SDK allows developers to implement custom error handling logic.
Default Behaviour
By default, only some requests will throw. If the response status code is 4xx
, then an exception will be thrown.
If the response status code is 5xx
, then the returned object will contain an error
property.
Customise Error Handling
Axios
The underlying HTTP request provider is Axios.
Server responded with an error
To change the error handling behaviour, you can replace the error handling function.
Async
customErrorResponseHandler
should be an async method.
import { errorHandling } from "cherry.ai";
const customErrorResponseHandler = async (axiosResponse) => {
console.warn(axiosResponse);
console.warn(`Server responded: ${axiosResponse.statusText}`);
throw axiosResponse.data;
};
export const configure = () => {
errorHandling.setErrorResponseHandler(customErrorResponseHandler);
};