kopia lustrzana https://github.com/cloudflare/wildebeest
Merge pull request #50 from cloudflare/internal-server-error
reuse generateErrorResponse in errorHandling functionpull/58/head
commit
a82098ada3
|
@ -11,7 +11,7 @@ const headers = {
|
|||
|
||||
function generateErrorResponse(error: string, status: number, errorDescription?: string): Response {
|
||||
const res: ErrorResponse = {
|
||||
error: `${error}. ` + 'If the problem persists please contact your instance administrator.',
|
||||
error: `${error}. If the problem persists please contact your instance administrator.`,
|
||||
...(errorDescription ? { error_description: errorDescription } : {}),
|
||||
}
|
||||
return new Response(JSON.stringify(res), { headers, status })
|
||||
|
@ -36,3 +36,7 @@ export function timelineMissing(): Response {
|
|||
export function clientUnknown(): Response {
|
||||
return generateErrorResponse(`The client is unknown or invalid`, 403)
|
||||
}
|
||||
|
||||
export function internalServerError(): Response {
|
||||
return generateErrorResponse('Internal Server Error', 500)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { internalServerError } from '../errors'
|
||||
|
||||
/**
|
||||
* A Pages middleware function that logs errors to the console and responds with 500 errors and stack-traces.
|
||||
*/
|
||||
|
@ -5,7 +7,7 @@ export async function errorHandling(context: EventContext<unknown, any, any>) {
|
|||
try {
|
||||
return await context.next()
|
||||
} catch (err: any) {
|
||||
console.log(err.stack)
|
||||
return new Response(`${err.message}\n${err.stack}`, { status: 500 })
|
||||
console.error(err)
|
||||
return internalServerError()
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue