Node js library - Error codes -- Documentation Wrong?

Hello everyone, I am using the Node js library. I don’t know what is the correct way to handle the errors, because the docs mention the error codes in this format: “InvalidRequestError” but then when I check the error object I have “invalid_request_error”. Can I handle other errors like “RateLimitError” by just validating it as “rate_limit_error” ?

One more thing, is the property “type” the correct property I have to check in order to handle the errors ? i mean can I trust this property will not be null or undefined ? (of course when the error is present)

Here is an example of the error object I got:

{
  status: 401,
  headers: ...headers,
  request_id: '7985fa3457eb2179f30356f8e4dc8eb4',
  error: {
    message: 'message',
    type: 'invalid_request_error',
    param: null,
    code: 'invalid_api_key'
  },
  code: 'invalid_api_key',
  param: null,
  type: 'invalid_request_error'
}

Thanks a lot

1 Like

Welcome to the dev forum… and with a decent first post, I might add. :slight_smile:

If you have links/screenhots, there’s a documentation category here where you can post. Sounds like an error in the docs, though.

I’d trust what you’re getting back from the API…

Again, welcome. Hope you stick around. We’ve got a great dev community growing here.

Thanks for your welcome!

Of course, on the docs you can find both Api Errors and Python Library Errors but for the Api Errors the docs don’t show any schema or object or property that you can use to identify and handle the possible errors, the docs only show the status-code related to each error but this is not very useful since there are many responses with these status-codes.

I find out the invalid_request_error because this is a simple error that you can cause by changing the api-key or passing an invalid param, but there are other errors like “Rate limit reached” or “Engine overloaded” that are very important to handle in production and they are not easy to simulate or trigger manually. So at this moment, I am just trusting in this only error response.

I may be wrong or I may not have done enough research, but I hope the docs can be updated soon to prevent any failure or unhandled exceptions in the apps that use this Node js library.

If someone knows more about this topic or has more experience using this library I will be grateful for any help. Thanks again.