Error handling

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.

Usage

The following code sample is an example of how to implement the error handling logic:

Copy
Copied
const res = await sdk.request({url: "https://api.com"})
if (res.status !== 200) {
    throw new sdk.errors.ResponseError("Failed to fetch API")
}

Error types

The following error types are available to use without any custom configurations:

  • ValidationError
  • ExpiredAuthError
  • RefreshAuthError
  • ResponseError

Custom errors

If the available errors do not meet your needs, you can also create a custom error to suit your needs.

Copy
Copied
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)
}
We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.