To properly catch and handle errors, the sdk provides a list of errors that can be used at any place in your app integration. All these errors are available under sdk.errors.
The following code sample is an example of how to implement the error handling logic:
const res = await sdk.request({url: "https://api.com"})
if (res.status !== 200) {
throw new sdk.errors.ResponseError("Failed to fetch API")
}The following error types are available to use without any custom configurations:
ValidationErrorExpiredAuthErrorRefreshAuthErrorResponseError
If the available errors do not meet your needs, you can also create a custom error to suit your needs.
class MyCustomError extends Error {
constructor(message) {
super(message);
this.type = "my_custom_error";
}
}
const res = await sdk.request({url: "https://api.com"})
if (res.status !== 200) {
throw new MyCustomError(res.data)
}