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(medusa): Expose error handler from middlewares #4609

Merged
merged 3 commits into from
Jul 27, 2023

Conversation

zhangpengchen
Copy link
Contributor

When defining custom endpoints, you would like to use

import { errorHandler } from "@medusajs/medusa"

instead of

import errorHandler from "@medusajs/medusa/dist/api/middlewares/error-handler"

e.g.

import { Router } from "express"
import store from "./routes/store"
import { errorHandler } from "@medusajs/medusa"

export default (rootDirectory: string): Router | Router[] => {
  const app = Router()
  
  store(app)

  app.use(errorHandler())

  return app;
}

Finally, the custom endpoints can return 400 Bad Request instead of 500 Internal Server Error.

@zhangpengchen zhangpengchen requested a review from a team as a code owner July 26, 2023 20:41
@vercel
Copy link

vercel bot commented Jul 26, 2023

@zhangpengchen is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link

changeset-bot bot commented Jul 26, 2023

🦋 Changeset detected

Latest commit: b090ede

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

This PR includes changesets to release 1 package
Name Type
@medusajs/medusa 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
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.

LGTM, thanks!

@olivermrbl olivermrbl changed the title feat: Expose error handler from middlewares feat(medusa): Expose error handler from middlewares Jul 27, 2023
@olivermrbl olivermrbl merged commit f18f1b9 into medusajs:develop Jul 27, 2023
@github-actions github-actions bot mentioned this pull request Jul 27, 2023
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.

2 participants