Skip to content

Commit

Permalink
Fix decorating errors
Browse files Browse the repository at this point in the history
  • Loading branch information
javivelasco committed Jul 21, 2022
1 parent 7f3588b commit fa883be
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/next/server/web/sandbox/context.ts
Expand Up @@ -256,6 +256,7 @@ Learn More: https://nextjs.org/docs/messages/middleware-dynamic-wasm-compilation
},
})

const decorateUnhandledError = getDecorateUnhandledError(runtime)
runtime.context.addEventListener('unhandledrejection', decorateUnhandledError)
runtime.context.addEventListener('error', decorateUnhandledError)

Expand Down Expand Up @@ -346,8 +347,11 @@ Learn more: https://nextjs.org/docs/api-reference/edge-runtime`)
}
}

function decorateUnhandledError(error: any) {
if (error instanceof Error) {
decorateServerError(error, 'edge-server')
function getDecorateUnhandledError(runtime: EdgeRuntime) {
const EdgeRuntimeError = runtime.evaluate(`Error`)
return (error: any) => {
if (error instanceof EdgeRuntimeError) {
decorateServerError(error, 'edge-server')
}
}
}

0 comments on commit fa883be

Please sign in to comment.