PaddleHQ / paddle-node-sdk

Node.js SDK for working with the Paddle API in server-side apps.
https://developer.paddle.com/
Apache License 2.0
28 stars 5 forks source link

[Feature]: add error handling example #7

Closed jobcespedes closed 4 months ago

jobcespedes commented 5 months ago

Tell us about your feature request

Add an example to handle a particular error response, for instance 409 conflict

What problem are you looking to solve?

Properly handle a particular error response

Additional context

No response

How important is this suggestion to you?

Nice to have

vijayasingam-paddle commented 4 months ago

Hi @jobcespedes, Sorry for the delay in response.

All of our error messages will be of type ApiError

You can handle any particular error type within your catch block using the code property. For example, to handle conflict error

try {
  // Call functions from the SDK
} catch (e: any) {
  // e.code will always follow the error code defined in our documentation
  if (e.code === 'conflict') {
    // Handle Conflict error
  }
}

Unfortunately the class ApiError is not exported as part of this package, I will fix that shortly so that we can typecast the error object within the catch block.

We will also update our documentation to make this clear.

Please let us know if we can help with anything else.

Thank you.