Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
catch all unhandled errors or bad responses
const spirit = require("spirit").node
const catchall = (handler) => (request) => handler(request).then((resp) => {
// something beforehand gave a bad response
// set our own custom message
if (!spirit.is_response(resp)) {
return { status: 500, headers: {}, body: "generic error message because of bad response" }
}
return resp
// something beforehand threw an error
// set a custom catch all message
}).catch((err) => {
return { status: 500, headers: {}, body: "generic error message because of thrown error" }
})
http.createServer(spirit.adapter(app, [catchall, other_middleware, ...]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.