Skip to content

Commit

Permalink
detect error parameter instance type and console accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
arbazsiddiqui committed Nov 19, 2017
1 parent 451506d commit 1a1209c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ const send = (res, code, obj = null) => {
res.end(str)
}

const sendError = (req, res, { statusCode, status, message, stack }) => {
statusCode = statusCode || status
message = statusCode ? message : 'Internal Server Error'
send(res, statusCode || 500, DEV ? stack : message)
console.error(stack)
const sendError = (req, res, errorObj) => {
const statusCode = errorObj.statusCode || errorObj.status
const message = statusCode ? errorObj.message : 'Internal Server Error'
send(res, statusCode || 500, DEV ? errorObj.stack : message)
if (errorObj instanceof Error) {
console.error(errorObj.stack)
} else {
console.warn('thrown error must be an instance Error')
}
}

exports.send = send
Expand Down

0 comments on commit 1a1209c

Please sign in to comment.