Respond to Adri's feedback.

This commit is contained in:
Sam Rose 2025-03-03 12:19:59 +00:00
parent aedad69a47
commit 0d2e6d6f5a
No known key found for this signature in database
2 changed files with 24 additions and 20 deletions

View File

@ -146,8 +146,8 @@ function applyRoutes(
addMiddleware(endpoints.read, mapperMiddleware, { output: true })
addMiddleware(endpoints.write, mapperMiddleware, { output: true })
if (env.isTest()) {
addMiddleware(endpoints.read, testErrorHandling)
addMiddleware(endpoints.write, testErrorHandling)
addMiddleware(endpoints.read, testErrorHandling())
addMiddleware(endpoints.write, testErrorHandling())
}
addToRouter(endpoints.read)
addToRouter(endpoints.write)

View File

@ -1,13 +1,16 @@
import { Ctx } from "@budibase/types"
import environment from "../../../../environment"
export default async (ctx: Ctx, next: any) => {
export default () => {
if (!environment.isTest()) {
throw new Error("This middleware is only for testing")
}
return async (ctx: Ctx, next: any) => {
try {
await next()
} catch (err: any) {
if (
!(environment.isTest() && ctx.headers["x-budibase-include-stacktrace"])
) {
if (!ctx.headers["x-budibase-include-stacktrace"]) {
throw err
}
@ -21,4 +24,5 @@ export default async (ctx: Ctx, next: any) => {
ctx.status = status
ctx.body = { status, message: error.message, stack: error.stack }
}
}
}