koa-better-error-handler
Advanced tools
Comparing version 3.0.5 to 4.0.0
@@ -1,1 +0,1 @@ | ||
{"processes":{"5fb48b36-29e6-4f3c-8897-1e46b275f845":{"parent":null,"children":["853d4f9a-6926-400c-9e21-510b3afeea74"]},"853d4f9a-6926-400c-9e21-510b3afeea74":{"parent":"5fb48b36-29e6-4f3c-8897-1e46b275f845","children":[]}},"files":{"/Users/jack/Projects/koa-better-error-handler/lib/index.js":["853d4f9a-6926-400c-9e21-510b3afeea74"]},"externalIds":{}} | ||
{"processes":{"22bdf556-8b74-4299-a668-9001f4ae3c99":{"parent":null,"children":["4ad14f3d-d452-40d2-adde-d9e7fa67525f"]},"4ad14f3d-d452-40d2-adde-d9e7fa67525f":{"parent":"22bdf556-8b74-4299-a668-9001f4ae3c99","children":[]}},"files":{"/Users/jack/Projects/koa-better-error-handler/lib/index.js":["4ad14f3d-d452-40d2-adde-d9e7fa67525f"]},"externalIds":{}} |
@@ -17,8 +17,10 @@ "use strict"; | ||
const camelCase = require('camelcase'); | ||
const capitalize = require('capitalize'); | ||
const camelCase = require('camelcase'); | ||
const co = require('co'); | ||
const htmlToText = require('html-to-text'); | ||
const humanize = require('humanize-string'); | ||
@@ -99,3 +101,4 @@ | ||
this.status = this.statusCode; | ||
this.body = new Boom.Boom(err.message, { | ||
const friendlyAPIMessage = makeAPIFriendly(this, err.message); | ||
this.body = new Boom.Boom(friendlyAPIMessage, { | ||
statusCode: err.status | ||
@@ -199,2 +202,13 @@ }).output.payload; // set any additional error headers specified | ||
function makeAPIFriendly(ctx, message) { | ||
if (!ctx.api) return message; | ||
message = htmlToText.fromString(message, { | ||
wordwrap: false, | ||
linkHrefBaseUrl: process.env.ERROR_HANDLER_BASE_URL ? process.env.ERROR_HANDLER_BASE_URL : '', | ||
hideLinkHrefIfSameAsText: true, | ||
ignoreImage: true | ||
}); | ||
return message; | ||
} | ||
function parseValidationError(ctx, err) { | ||
@@ -235,3 +249,3 @@ // translate messages | ||
err.message = ctx.api ? errors.join(', ') : `<ul class="text-left mb-0"><li>${errors.join('</li><li>')}</li></ul>`; | ||
err.message = makeAPIFriendly(ctx, `<ul class="text-left mb-0"><li>${errors.join('</li><li>')}</li></ul>`); | ||
} // this ensures the error shows up client-side | ||
@@ -238,0 +252,0 @@ |
{ | ||
"name": "koa-better-error-handler", | ||
"description": "A better error-handler for Lad and Koa. Makes `ctx.throw` awesome (best used with koa-404-handler)", | ||
"version": "3.0.5", | ||
"version": "4.0.0", | ||
"author": "Nick Baugh <niftylettuce@gmail.com>", | ||
@@ -16,27 +16,28 @@ "bugs": "https://github.com/ladjs/koa-better-error-handler/issues", | ||
"dependencies": { | ||
"@hapi/boom": "^9.0.0", | ||
"camelcase": "^5.3.1", | ||
"capitalize": "^2.0.1", | ||
"@hapi/boom": "^9.1.0", | ||
"camelcase": "^6.0.0", | ||
"capitalize": "^2.0.3", | ||
"co": "^4.6.0", | ||
"debug": "^4.1.1", | ||
"html-to-text": "^5.1.1", | ||
"humanize-string": "^2.1.0", | ||
"lodash": "^4.17.15", | ||
"statuses": "^1.5.0", | ||
"statuses": "^2.0.0", | ||
"toidentifier": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.8.3", | ||
"@babel/core": "^7.8.3", | ||
"@babel/preset-env": "^7.8.3", | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.9.6", | ||
"@babel/preset-env": "^7.9.6", | ||
"@commitlint/cli": "^8.3.5", | ||
"@commitlint/config-conventional": "^8.3.4", | ||
"@koa/router": "^8.0.6", | ||
"@koa/router": "^8.0.8", | ||
"ava": "2.x", | ||
"codecov": "^3.6.2", | ||
"cross-env": "6.x", | ||
"eslint": "^6.8.0", | ||
"codecov": "^3.6.5", | ||
"cross-env": "^7.0.2", | ||
"eslint": "6.x", | ||
"eslint-config-xo-lass": "^1.0.3", | ||
"eslint-plugin-node": "^11.0.0", | ||
"fixpack": "^2.3.1", | ||
"husky": "3.x", | ||
"eslint-plugin-node": "^11.1.0", | ||
"fixpack": "^3.0.6", | ||
"husky": "^4.2.5", | ||
"koa": "^2.11.0", | ||
@@ -49,9 +50,9 @@ "koa-404-handler": "^0.0.2", | ||
"koa-redis": "^4.0.1", | ||
"lint-staged": "^10.0.4", | ||
"nyc": "^15.0.0", | ||
"redis": "^2.8.0", | ||
"remark-cli": "^7.0.1", | ||
"remark-preset-github": "^0.0.16", | ||
"lint-staged": "^10.2.2", | ||
"nyc": "^15.0.1", | ||
"redis": "^3.0.2", | ||
"remark-cli": "^8.0.0", | ||
"remark-preset-github": "^1.0.0", | ||
"supertest": "^4.0.2", | ||
"xo": "^0.25.3" | ||
"xo": "0.25" | ||
}, | ||
@@ -58,0 +59,0 @@ "engines": { |
@@ -220,2 +220,9 @@ # koa-better-error-handler | ||
## API Friendly Messages | ||
By default if `ctx.api` is true, then [html-to-text](https://github.com/werk85/node-html-to-text) will be invoked upon the `err.message`, thus converting all the HTML markup into text format. | ||
You can also specify a base URI in the environment variable for rendering as `process.env.ERROR_HANDLER_BASE_URL`, e.g. `BERROR_HANDLER_BASE_URL=https://example.com` (omit trailing slash), and any HTML links such as `<a href="/foo/bar/baz">Click here</a>` will be converted to `[Click here][1]` with a `[1]` link appended of `https://example.com/foo/bar/baz`. | ||
## License | ||
@@ -222,0 +229,0 @@ |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
53388
331
247
10
4
+ Addedhtml-to-text@^5.1.1
+ Addedcamelcase@6.3.0(transitive)
+ Addeddom-serializer@0.2.2(transitive)
+ Addeddomelementtype@1.3.12.3.0(transitive)
+ Addeddomhandler@2.4.2(transitive)
+ Addeddomutils@1.7.0(transitive)
+ Addedentities@1.1.22.2.0(transitive)
+ Addedhe@1.2.0(transitive)
+ Addedhtml-to-text@5.1.1(transitive)
+ Addedhtmlparser2@3.10.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstatuses@2.0.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedcamelcase@5.3.1(transitive)
- Removedstatuses@1.5.0(transitive)
Updated@hapi/boom@^9.1.0
Updatedcamelcase@^6.0.0
Updatedcapitalize@^2.0.3
Updatedstatuses@^2.0.0