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

feat: Normalize known DB errors to a MedusaError when possible #6922

Merged
merged 1 commit into from
Apr 4, 2024

Conversation

sradevski
Copy link
Member

Before we would swallow the error and return a generic error to the user. This will provide more information to the caller if it is one of the known errors.

@sradevski sradevski requested a review from a team as a code owner April 3, 2024 15:07
Copy link

changeset-bot bot commented Apr 3, 2024

🦋 Changeset detected

Latest commit: c1dff52

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@medusajs/utils Minor
@medusajs/promotion Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference 🔄 Building (Inspect) Visit Preview Apr 4, 2024 6:59pm
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 4, 2024 6:59pm
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
docs-ui ⬜️ Ignored (Inspect) Visit Preview Apr 4, 2024 6:59pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Apr 4, 2024 6:59pm

Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

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

great addition @sradevski!

return null
}

return {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also return the name of the constraint (err.constraint)? I believe adding it to the message in parentheses would be helpful.

Copy link
Member Author

Choose a reason for hiding this comment

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

@carlos-r-l-rodrigues I think that might be too much of an implementation detail that we leak to the FE. What would be nice though is to have it as part of MedusaError in some form and then we plug that into some error logging/tracing before responding to the end user, but I think we can tackle that later when we integrate better with some tracing library

Copy link
Contributor

Choose a reason for hiding this comment

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

Here is the DAL utils, so I expect the backend to have access to these properties.
it is alright to throw from here directly to the front end, but we need to have access to the details on the backend, even to handle errors differently based on the constraint name.

Copy link
Member Author

Choose a reason for hiding this comment

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

@carlos-r-l-rodrigues yeah definitely, whichi s why I think we should add the constraint on MedusaError as a separate field, but not as part of the message. I suggest we just handle that separately though

@sradevski sradevski force-pushed the feat/normalize-db-errors branch from 6bd4bae to c1dff52 Compare April 4, 2024 18:56
@kodiakhq kodiakhq bot merged commit 20e8df9 into develop Apr 4, 2024
24 checks passed
@kodiakhq kodiakhq bot deleted the feat/normalize-db-errors branch April 4, 2024 19:13
@github-actions github-actions bot mentioned this pull request Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants