Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cb is not a function at fallbackErrorHandler #5296

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 19 additions & 12 deletions lib/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,25 @@ const rootErrorHandler = {
}
}

function defaultErrorHandlerCB (reply, payload) {
try {
reply.raw.writeHead(reply.raw.statusCode, reply[kReplyHeaders])
} catch (error) {
reply.log.warn(
{ req: reply.request, res: reply, err: error },
error && error.message
)
reply.raw.writeHead(reply.raw.statusCode)
}
reply.raw.end(payload)
}

function handleError (reply, error, cb) {
reply[kReplyIsRunningOnErrorHook] = false

const context = reply[kRouteContext]
if (reply[kReplyNextErrorHandler] === false) {
fallbackErrorHandler(error, reply, function (reply, payload) {
try {
reply.raw.writeHead(reply.raw.statusCode, reply[kReplyHeaders])
} catch (error) {
reply.log.warn(
{ req: reply.request, res: reply, err: error },
error && error.message
)
reply.raw.writeHead(reply.raw.statusCode)
}
reply.raw.end(payload)
})
fallbackErrorHandler(error, reply, defaultErrorHandlerCB)
return
}
const errorHandler = reply[kReplyNextErrorHandler] || context.errorHandler
Expand Down Expand Up @@ -124,6 +126,11 @@ function fallbackErrorHandler (error, reply, cb) {

reply[kReplyHeaders]['content-length'] = '' + Buffer.byteLength(payload)

if (typeof cb !== 'function') {
defaultErrorHandlerCB(reply, payload)
return
}

cb(reply, payload)
}

Expand Down