Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
feat(error): use newer youch for error display
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jan 28, 2017
1 parent 400646b commit 2771302
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions app/Listeners/Http.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Env = use('Env')
const Ouch = use('youch')
const Youch = use('youch')
const Http = exports = module.exports = {}

/**
Expand All @@ -12,23 +12,23 @@ const Http = exports = module.exports = {}
* @param {Object} response
*/
Http.handleError = function * (error, request, response) {
const status = error.status || 500

/**
* DEVELOPMENT REPORTER
*/
if (Env.get('NODE_ENV') === 'development') {
const ouch = new Ouch().pushHandler(
new Ouch.handlers.PrettyPageHandler('blue', null, 'sublime')
)
ouch.handleException(error, request.request, response.response, (output) => {
console.error(error.stack)
})
const youch = new Youch(error, request.request)
const type = request.accepts('json', 'html')
const formatMethod = type === 'json' ? 'toJSON' : 'toHTML'
const formattedErrors = yield youch[formatMethod]()
response.status(status).send(formattedErrors)
return
}

/**
* PRODUCTION REPORTER
*/
const status = error.status || 500
console.error(error.stack)
yield response.status(status).sendView('errors/index', {error})
}
Expand Down

0 comments on commit 2771302

Please sign in to comment.