{"size": 466, "ext": "js", "max_stars_repo_path": "src/middleware/error-handler.js", "max_stars_repo_name": "alanbueno/rasp-node-blink", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/middleware/error-handler.js", "max_issues_repo_name": "alanbueno/rasp-node-blink", "max_issues_repo_issues_event_min_datetime": "2020-02-17T05:02:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-02T04:40:43.000Z", "max_forks_repo_path": "src/middleware/error-handler.js", "max_forks_repo_name": "alanbueno/rasp-node-blink", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 21, "max_forks_count": null, "avg_line_length": 25.8888888889, "max_line_length": 99, "alphanum_fraction": 0.6459227468}
const Boom = require('boom')

module.exports = async (ctx, next) => {
  try {
    await next()

    if (!ctx._matchedRoute) { ctx.throw(Boom.notFound('Route not found')) }
  } catch (error) {
    ctx.status = error.isJoi ? 400 : error.isBoom ? error.output.statusCode : (error.status || 500)

    const boomError = Boom.boomify(error, { statusCode: ctx.status })

    ctx.body = boomError.data || boomError.output.payload

    ctx.app.emit('error', boomError)
  }
}
