hapi-dev-errors
Advanced tools
Comparing version 2.1.0 to 2.2.0
# Changelog | ||
## Version 2.2.0 (2018-06-02) | ||
- `add` JSON response for CLI requests (cURL, Postman, wget) (thank you @pi0) | ||
## Version 2.1.0 (2018-02-12) | ||
@@ -4,0 +7,0 @@ - `add` status code to Youch error and show it in the view |
@@ -39,2 +39,5 @@ 'use strict' | ||
// helper function to test if string matches a value | ||
const matches = (str, regex) => str && str.match(regex) | ||
// extend the request lifecycle at `onPreResponse` | ||
@@ -49,2 +52,3 @@ // to change the default error handling behavior (if enabled) | ||
const accept = request.raw.req.headers.accept | ||
const agent = request.raw.req.headers['user-agent'] | ||
const statusCode = error.output.statusCode | ||
@@ -63,4 +67,13 @@ | ||
// take priority: check header if request is in CLI | ||
if (matches(agent, /curl|wget|postman/i)) { | ||
const formattedJSON = JSON.stringify(Object.assign({}, errorResponse, { | ||
stacktrace: errorResponse.stacktrace.replace(/<\/?mark>/g, '').split('\n').map(s => s.trim()) | ||
}), null, 2) | ||
return h.response(formattedJSON).code(statusCode).type('application/json') | ||
} | ||
// take priority: check header if there’s a JSON REST request | ||
if (accept && accept.match(/json/)) { | ||
if (matches(accept, /json/)) { | ||
return h.response(errorResponse).code(statusCode) | ||
@@ -67,0 +80,0 @@ } |
{ | ||
"name": "hapi-dev-errors", | ||
"description": "Return better error details and skip the look at command line to catch the issue.", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"author": "Future Studio <info@futurestud.io>", | ||
@@ -6,0 +6,0 @@ "bugs": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
22
577
0
239502