Skip to content

Commit

Permalink
Merge branch 'develop' into feat/pricing-module-price-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
riqwan authored Nov 15, 2023
2 parents 0e73a00 + 2947f57 commit b4548c8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-books-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): Update wrapHandler so that it is also able to catch errors for sync handlers
5 changes: 5 additions & 0 deletions .changeset/seven-forks-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/admin-ui": patch
---

fix(admin-ui): Resolves an issue where decimal numbers would be stripped when the locale uses commas as the decimal separator
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,7 @@ const Cell = React.forwardRef<HTMLInputElement, CellProps>(
? formatValue({
value: strippedValue.replace(/,/g, "."), // If the current locale uses commas as decimal separators, then we need to replace them with dots.
decimalScale: decimalScale ?? 0,
decimalSeparator: ".",
disableGroupSeparators: true,
})
: ""
Expand Down
11 changes: 9 additions & 2 deletions packages/medusa/src/api/middlewares/await-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { NextFunction, Request, RequestHandler, Response } from "express"

type handler = (req: Request, res: Response) => Promise<void>

/**
* @deprecated use `import { wrapHandler } from "@medusajs/utils"`
*/
export default (fn: handler): RequestHandler => {
return (req: Request, res: Response, next: NextFunction) => {
return async (req: Request, res: Response, next: NextFunction) => {
if (req?.errors?.length) {
return res.status(400).json({
errors: req.errors,
Expand All @@ -12,7 +15,11 @@ export default (fn: handler): RequestHandler => {
})
}

return fn(req, res).catch(next)
try {
return await fn(req, res)
} catch (err) {
next(err)
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/medusa/src/loaders/helpers/routing/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { promiseAll } from "@medusajs/utils"
import { promiseAll, wrapHandler } from "@medusajs/utils"
import cors from "cors"
import { Router, json, text, urlencoded, type Express } from "express"
import { readdir } from "fs/promises"
Expand All @@ -9,7 +9,6 @@ import {
authenticateCustomer,
errorHandler,
requireCustomerAuthentication,
wrapHandler,
} from "../../../api/middlewares"
import { ConfigModule } from "../../../types/global"
import logger from "../../logger"
Expand Down
8 changes: 6 additions & 2 deletions packages/utils/src/common/wrap-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NextFunction, Request, RequestHandler, Response } from "express"
type handler = (req: Request, res: Response) => Promise<void>

export const wrapHandler = (fn: handler): RequestHandler => {
return (req: Request, res: Response, next: NextFunction) => {
return async (req: Request, res: Response, next: NextFunction) => {
const req_ = req as Request & { errors?: Error[] }
if (req_?.errors?.length) {
return res.status(400).json({
Expand All @@ -13,7 +13,11 @@ export const wrapHandler = (fn: handler): RequestHandler => {
})
}

return fn(req, res).catch(next)
try {
return await fn(req, res)
} catch (err) {
next(err)
}
}
}

Expand Down

0 comments on commit b4548c8

Please sign in to comment.