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

Simplify logic for looking-up boom error type #11

Merged
merged 1 commit into from Feb 2, 2021

Conversation

devinivy
Copy link
Member

While working on #10 I noticed there there might be an opportunity to simplify some of the logic used to look-up a boom error type from an objection error type.

If I understand correctly this logic is looking for an exact constructor match:

if (error instanceof internals.dbErrorMapping[key][i] && error.constructor.name === internals.dbErrorMapping[key][i].name) {
    return Boom[key](options.includeMessage ? error.message : null);
}

The idea here is to use a Map keyed by objection error classes to do a direct lookup on the error's constructor to see if it is of one of those classes.

@devinivy
Copy link
Member Author

The source of the failing test is actually a recent change to objection. I have a question out to Sami about whether the fix should be to objection or our test suite: Vincit/objection.js@aa1e095#r46314524

@devinivy devinivy added the feature New functionality or improvement label Jan 24, 2021
Copy link
Collaborator

@optii optii left a comment

Choose a reason for hiding this comment

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

Looks good to me. If I remember correctly objection didn't expose all the errors directly at the time of creation, they where exposed via objection-db-errors iirc and I think there where some edge cases that couldn't be caught with the Map, hence the loop & check of instanceof & constructor.name. but this is definitely better ! 👍

@devinivy devinivy added this to the 3.0.0 milestone Jan 29, 2021
@optii optii merged commit 35ff59c into master Feb 2, 2021
@optii optii deleted the simplify-error-lookup branch February 2, 2021 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants