Print stack traces from inside request handler.
This commit is contained in:
parent
e309282ff7
commit
8488ff4144
|
@ -1,5 +1,6 @@
|
||||||
import { APIError } from "@budibase/types"
|
import { APIError } from "@budibase/types"
|
||||||
import * as errors from "../errors"
|
import * as errors from "../errors"
|
||||||
|
import environment from "../environment"
|
||||||
|
|
||||||
export async function errorHandling(ctx: any, next: any) {
|
export async function errorHandling(ctx: any, next: any) {
|
||||||
try {
|
try {
|
||||||
|
@ -14,15 +15,21 @@ export async function errorHandling(ctx: any, next: any) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
const error = errors.getPublicError(err)
|
if (environment.isTest()) {
|
||||||
const body: APIError = {
|
ctx.body = {
|
||||||
message: err.message,
|
message: err.message,
|
||||||
status: status,
|
status: status,
|
||||||
validationErrors: err.validation,
|
error: errors.getPublicError(err),
|
||||||
error,
|
stack: err.stack,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.body = {
|
||||||
|
message: err.message,
|
||||||
|
status: status,
|
||||||
|
validationErrors: err.validation,
|
||||||
|
error: errors.getPublicError(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.body = body
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,11 +126,27 @@ export abstract class TestAPI {
|
||||||
const response = await request
|
const response = await request
|
||||||
|
|
||||||
if (response.status !== status) {
|
if (response.status !== status) {
|
||||||
throw new Error(
|
let message = `Expected status ${status} but got ${response.status}`
|
||||||
`Expected status ${status} but got ${
|
|
||||||
response.status
|
const stack = response.body.stack
|
||||||
} with body ${JSON.stringify(response.body)}`
|
delete response.body.stack
|
||||||
)
|
|
||||||
|
if (response.body) {
|
||||||
|
message += `\n\nBody:`
|
||||||
|
const body = JSON.stringify(response.body, null, 2)
|
||||||
|
for (const line of body.split("\n")) {
|
||||||
|
message += `\n⏐ ${line}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack) {
|
||||||
|
message += `\n\nStack from request handler:`
|
||||||
|
for (const line of stack.split("\n")) {
|
||||||
|
message += `\n⏐ ${line}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expectations?.headersNotPresent) {
|
if (expectations?.headersNotPresent) {
|
||||||
|
|
Loading…
Reference in New Issue