chore(product): Improve product normalization and fix http router with tracing (#11724)
**What** - Improve product normalization and prevent over fetching data - Fix HTTP router wrap handler with tracing enabled
This commit is contained in:
committed by
GitHub
parent
e81deb49f8
commit
cc1309d370
@@ -0,0 +1,5 @@
|
||||
import { Request, Response } from "express"
|
||||
|
||||
export function GET(req: Request, res: Response) {
|
||||
throw new Error("Failed")
|
||||
}
|
||||
@@ -36,6 +36,22 @@ describe("RoutesLoader", function () {
|
||||
request = request_
|
||||
})
|
||||
|
||||
it("should be handled by the error handler when a route handler fails", async function () {
|
||||
const res = await request("GET", "/admin/fail", {
|
||||
adminSession: {
|
||||
jwt: {
|
||||
userId: "admin_user",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(res.status).toBe(500)
|
||||
console.log(res)
|
||||
expect(res.text).toBe(
|
||||
'{"code":"unknown_error","type":"unknown_error","message":"An unknown error occurred."}'
|
||||
)
|
||||
})
|
||||
|
||||
it("should return a status 200 on GET admin/order/:id", async function () {
|
||||
const res = await request("GET", "/admin/orders/1000", {
|
||||
adminSession: {
|
||||
|
||||
@@ -9,6 +9,18 @@ describe("Routes loader", () => {
|
||||
|
||||
expect(loader.getRoutes()).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"absolutePath": "${BASE_DIR}/admin/fail/route.ts",
|
||||
"handler": [Function],
|
||||
"isRoute": true,
|
||||
"matcher": "/admin/fail",
|
||||
"method": "GET",
|
||||
"optedOutOfAuth": false,
|
||||
"relativePath": "/admin/fail/route.ts",
|
||||
"shouldAppendAdminCors": true,
|
||||
"shouldAppendAuthCors": false,
|
||||
"shouldAppendStoreCors": false,
|
||||
},
|
||||
{
|
||||
"absolutePath": "${BASE_DIR}/admin/orders/[id]/route.ts",
|
||||
"handler": [Function],
|
||||
@@ -205,6 +217,18 @@ describe("Routes loader", () => {
|
||||
|
||||
expect(loader.getRoutes()).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"absolutePath": "${BASE_DIR}/admin/fail/route.ts",
|
||||
"handler": [Function],
|
||||
"isRoute": true,
|
||||
"matcher": "/admin/fail",
|
||||
"method": "GET",
|
||||
"optedOutOfAuth": false,
|
||||
"relativePath": "/admin/fail/route.ts",
|
||||
"shouldAppendAdminCors": true,
|
||||
"shouldAppendAuthCors": false,
|
||||
"shouldAppendStoreCors": false,
|
||||
},
|
||||
{
|
||||
"absolutePath": "${BASE_DIR}/admin/orders/[id]/route.ts",
|
||||
"handler": [Function],
|
||||
|
||||
@@ -104,25 +104,25 @@ export class ApiLoader {
|
||||
if ("isRoute" in route) {
|
||||
logger.debug(`registering route ${route.method} ${route.matcher}`)
|
||||
const handler = ApiLoader.traceRoute
|
||||
? ApiLoader.traceRoute(wrapHandler(route.handler), {
|
||||
? ApiLoader.traceRoute(route.handler, {
|
||||
route: route.matcher,
|
||||
method: route.method,
|
||||
})
|
||||
: wrapHandler(route.handler)
|
||||
: route.handler
|
||||
|
||||
this.#app[route.method.toLowerCase()](route.matcher, handler)
|
||||
this.#app[route.method.toLowerCase()](route.matcher, wrapHandler(handler))
|
||||
return
|
||||
}
|
||||
|
||||
if (!route.methods) {
|
||||
logger.debug(`registering global middleware for ${route.matcher}`)
|
||||
const handler = ApiLoader.traceMiddleware
|
||||
? (ApiLoader.traceMiddleware(wrapHandler(route.handler), {
|
||||
? (ApiLoader.traceMiddleware(route.handler, {
|
||||
route: route.matcher,
|
||||
}) as RequestHandler)
|
||||
: (wrapHandler(route.handler) as RequestHandler)
|
||||
: (route.handler as RequestHandler)
|
||||
|
||||
this.#app.use(route.matcher, handler)
|
||||
this.#app.use(route.matcher, wrapHandler(handler))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user