Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw custom errors #51

Merged
merged 1 commit into from
Jan 10, 2023
Merged

Throw custom errors #51

merged 1 commit into from
Jan 10, 2023

Conversation

m-mohr
Copy link
Collaborator

@m-mohr m-mohr commented Dec 22, 2022

I've added two custom error classes so that we can catch the errors separately.
I've also added individual error codes and the "variables" in the message to the text so that implementing libraries can catch and translate the error messages if they want.
Lastly, the prefixes in the exceptions have been removed and some error messages be simplified as they swallow up to users and should likely be a bit less "techy" (devs can enable the logging in the console).

I'm following the behavior for providing a "cause" as proposed here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause#providing_structured_data_as_the_error_cause

Related issue: radiantearth/stac-browser#123

@m-mohr m-mohr changed the title Throw custom errors so that we can catch them individually for i18n etc. Throw custom errors Dec 22, 2022
@m-mohr
Copy link
Collaborator Author

m-mohr commented Jan 4, 2023

@DanielJDufour Happy new year! Does this look goot to you, too?

Copy link
Member

@DanielJDufour DanielJDufour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome. In the future, we might consider if we want to define the Error Codes as constant variables and export them, but that's minor.

@DanielJDufour DanielJDufour merged commit 3741133 into main Jan 10, 2023
@m-mohr m-mohr deleted the custom-errors branch January 10, 2023 13:17
@DanielJDufour
Copy link
Member

Also, thanks for introducing me to the cause error property. I hadn't heard about it until you did!

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