easypost-node icon indicating copy to clipboard operation
easypost-node copied to clipboard

[Feat]: Have the base `ErrorClass` extend Error

Open craigmichaelmartin opened this issue 3 years ago • 2 comments

Feature Request Is New

  • [x] I have verified that the requested feature does not already exist or has not already been requested.

Description of the feature

👋 Good afternoon! Thank you for all your work on this project!

I was wondering if there is a reason ErrorClass doesn't extend Error (and update the internals a bit).

My thought is that throwing custom errors which are instancesof Error is more expected, and works better with tooling in the community (eg, error monitoring tooling like Sentry which expect instances of errors, and not objects).

I am only somewhat familiar with custom JavaScript error structures and its history with the introduction of custom error classes extending Error in ES2015, but would be happy to make a PR with these changes - if this is reasonable and desired.

Thanks again for EasyPost and all you do!

craigmichaelmartin avatar Jun 07 '22 21:06 craigmichaelmartin

Thanks for the proposal!

Sounds like a good idea to me, especially if it will make our library interact nicer with other tools.

If you want to take a crack at a PR, that'd be great!

nwithan8 avatar Jun 07 '22 22:06 nwithan8

@craigmichaelmartin thanks for the suggestion! We plan to overhaul error handling in all our libs very shortly and are in the planning stages as we speak. We'll keep you posted when this is complete.

Justintime50 avatar Sep 09 '22 16:09 Justintime50

One thing that was confusing/counterintuitive for us was the changing of the message error property to an object { value: message } instead of a string. This doesn't seem to provide any utility and is not what anyone would expect when handling errors. The code I'm referring to is here https://github.com/EasyPost/easypost-node/blob/master/src/errors/error.js#L5

Also agree on extending Error

mwhearty avatar Feb 09 '23 13:02 mwhearty

Hey @mwhearty , thanks for weighing in on this discussion and pointing this out.

We are right in the middle of a big rewrite of this library (part one in review here, feel free to comment: https://github.com/EasyPost/easypost-node/pull/345), which will include an overhaul of the Error class to fix some inconsistencies and oddities like this.

Be on the look out for a new major release of the Node library in the coming weeks!

nwithan8 avatar Feb 09 '23 17:02 nwithan8

Hello everyone, we would like to express our gratitude once again for bringing this to our attention. We are pleased to inform you that this issue has been resolved in #349, where we have just completed an overhaul of our error handling. There are now two types of errors: ApiError, which is specific to errors from the API endpoint and it extends to EasyPostError, and EasyPostError, which is a general error from the library, such as when no lowest rate can be found. EasyPostError extends to the built-in Node Error.

We are expecting to release the V6 overwrite within the next few weeks, so please stay tuned for that! I hope this information has been helpful to you. I am going to close this issue for now but please do not hesitate to let us know if you have any concerns, and thank you for choosing EasyPost 😄

jchen293 avatar Feb 22 '23 18:02 jchen293