fix(error): reorder error handling logic to respect handled flag

Move HTML generation after event.handled check to prevent unnecessary
error page generation for already handled errors.
This commit is contained in:
Daniel Philip Johnson 2025-01-17 14:13:26 +00:00
parent 5d74ae3c6b
commit 71ce7c3415

View File

@ -80,7 +80,10 @@ export default <NitroErrorHandler> async function errorhandler (error: H3Error,
return send(event, template(errorObject))
}
if (event.handled) { return }
const html = await youch.toHTML(error, {
title: `${errorObject.statusCode}`,
request: {
url,
method: event.method,
@ -88,8 +91,6 @@ export default <NitroErrorHandler> async function errorhandler (error: H3Error,
},
})
if (event.handled) { return }
for (const [header, value] of res.headers.entries()) {
setResponseHeader(event, header, value)
}