Skip to content

[60372] Return better error details from API#236

Merged
mrashed-dev merged 5 commits intomainfrom
mostafarashed/ch60372/node-sdk-type-missing-from-errors-dealer
Jun 4, 2021
Merged

[60372] Return better error details from API#236
mrashed-dev merged 5 commits intomainfrom
mostafarashed/ch60372/node-sdk-type-missing-from-errors-dealer

Conversation

@mrashed-dev
Copy link
Copy Markdown
Contributor

@mrashed-dev mrashed-dev commented Jun 1, 2021

Description

Previously, we would only return generally the error message. Now we return a custom error object (that extends Error) that properly stores all of the error values we get back from the API and sets them in a way that is more native than just returning a string.

Usage

The new NylasApiError class extends the Error class and both sets the build-in properties of Error and extends the error class to provide more values if needed. The following properties are made availalbe by the class:

  • name (string): The name of the error, derived from the API Errors page (e.g. Bad Request)
  • message (string): The error message returned from the API (e.g. No recipients specified)
  • statusCode (number): The status code returned from the API call (e.g. 400)
  • type (string): The type of error returned from the API (e.g. invalid_request_error)
  • missingFields (string[]): The array of fields that were missing in the call, if applicable (e.g. ["name", "email"])
  • serverError (string): The error returned by the provider (e.g. interaction_required)
  • stack (string): The stacktrace from JavaScript

License

I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.

Previously, we would only return generally the error message. Now we return a JSON with all the error details returned from the API.
@mrashed-dev mrashed-dev requested a review from AaronDDM June 1, 2021 00:30
@shortcut-integration
Copy link
Copy Markdown

This pull request has been linked to Clubhouse Story #60372: Node SDK - 'type' missing from errors (Dealer Inspire).

To prevent incompatibility and keep the flexibility we move the type into a class and make it an instance of Error
@mrashed-dev mrashed-dev requested a review from AaronDDM June 3, 2021 21:37
Error code mapping is based on the API Errors page in the Nylas developer guide. Also allows us to keep the error object as close to the response payload.
Comment thread src/models/NylasApiError.ts Outdated
For the sake of keeping things backwards compatible, we should keep the toString() the same. The point of this object should be to extend functionality and not break anything.
@mrashed-dev mrashed-dev requested a review from AaronDDM June 4, 2021 17:24
@mrashed-dev mrashed-dev merged commit 4d556c5 into main Jun 4, 2021
mrashed-dev added a commit that referenced this pull request Jun 9, 2021
New `nylas` v5.5.0 release bringing in the following new features:
* Replaced deprecated `request` library with `node-fetch` (#234)
* Add custom error class `NylasApiError` to add more error details returned from the API (#236)
* Add support for read only fields (#237)
* Enabled Nylas API v2.2 support (#237)

The new release also fixes the following:
* Fix bug where saving a `draft` object with an undefined `filesIds` would throw an error (#230)
* Fix typings for classes that extend `RestfulModelCollection` or `RestfulModelInstance` (#238)
@agtang96 agtang96 deleted the mostafarashed/ch60372/node-sdk-type-missing-from-errors-dealer branch April 5, 2023 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants