strong-error-handler 2.3.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +35 -0
- package/CHANGES.md +10 -0
- package/README.md +8 -0
- package/lib/content-negotiation.js +1 -1
- package/lib/data-builder.js +15 -23
- package/package.json +12 -12
package/.npmignore
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Logs
|
|
2
|
+
logs
|
|
3
|
+
*.log
|
|
4
|
+
npm-debug.log*
|
|
5
|
+
|
|
6
|
+
# Runtime data
|
|
7
|
+
pids
|
|
8
|
+
*.pid
|
|
9
|
+
*.seed
|
|
10
|
+
|
|
11
|
+
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
12
|
+
lib-cov
|
|
13
|
+
|
|
14
|
+
# Coverage directory used by tools like istanbul
|
|
15
|
+
coverage
|
|
16
|
+
|
|
17
|
+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
|
18
|
+
.grunt
|
|
19
|
+
|
|
20
|
+
# node-waf configuration
|
|
21
|
+
.lock-wscript
|
|
22
|
+
|
|
23
|
+
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
|
24
|
+
build/Release
|
|
25
|
+
|
|
26
|
+
# Dependency directory
|
|
27
|
+
node_modules
|
|
28
|
+
|
|
29
|
+
# Optional npm cache directory
|
|
30
|
+
.npm
|
|
31
|
+
|
|
32
|
+
# Optional REPL history
|
|
33
|
+
.node_repl_history
|
|
34
|
+
test
|
|
35
|
+
.travis.yml
|
package/CHANGES.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2018-06-12, Version 3.0.0
|
|
2
|
+
=========================
|
|
3
|
+
|
|
4
|
+
* Allow safeFields to work with arrays (shimks)
|
|
5
|
+
|
|
6
|
+
* run lint (shimks)
|
|
7
|
+
|
|
8
|
+
* drop node 4 from travis and update dependencies (shimks)
|
|
9
|
+
|
|
10
|
+
|
|
1
11
|
2018-03-05, Version 2.3.2
|
|
2
12
|
=========================
|
|
3
13
|
|
package/README.md
CHANGED
|
@@ -12,6 +12,14 @@ In production mode, `strong-error-handler` omits details from error responses to
|
|
|
12
12
|
|
|
13
13
|
In debug mode, `strong-error-handler` returns full error stack traces and internal details of any error objects to the client in the HTTP responses.
|
|
14
14
|
|
|
15
|
+
## Supported versions
|
|
16
|
+
|
|
17
|
+
Current|Long Term Support|Maintenance
|
|
18
|
+
:-:|:-:|:-:
|
|
19
|
+
3.x|2.x|1.x
|
|
20
|
+
|
|
21
|
+
Learn more about our LTS plan in [docs](http://loopback.io/doc/en/contrib/Long-term-support.html).
|
|
22
|
+
|
|
15
23
|
## Installation
|
|
16
24
|
|
|
17
25
|
```bash
|
package/lib/data-builder.js
CHANGED
|
@@ -8,16 +8,18 @@
|
|
|
8
8
|
var cloneAllProperties = require('../lib/clone.js');
|
|
9
9
|
var httpStatus = require('http-status');
|
|
10
10
|
|
|
11
|
-
module.exports =
|
|
11
|
+
module.exports = buildResponseData;
|
|
12
|
+
|
|
13
|
+
function buildResponseData(err, options) {
|
|
12
14
|
// Debugging mode is disabled by default. When turned on (in dev),
|
|
13
15
|
// all error properties (including) stack traces are sent in the response
|
|
14
|
-
|
|
16
|
+
const isDebugMode = options.debug;
|
|
15
17
|
|
|
16
|
-
if (Array.isArray(err)
|
|
17
|
-
|
|
18
|
+
if (Array.isArray(err)) {
|
|
19
|
+
return serializeArrayOfErrors(err, options);
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
const data = Object.create(null);
|
|
21
23
|
fillStatusCode(data, err);
|
|
22
24
|
|
|
23
25
|
if (typeof err !== 'object') {
|
|
@@ -29,35 +31,25 @@ module.exports = function buildResponseData(err, options) {
|
|
|
29
31
|
|
|
30
32
|
if (isDebugMode) {
|
|
31
33
|
fillDebugData(data, err);
|
|
32
|
-
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (data.statusCode >= 400 && data.statusCode <= 499) {
|
|
33
38
|
fillBadRequestError(data, err);
|
|
34
39
|
} else {
|
|
35
40
|
fillInternalError(data, err);
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
const safeFields = options.safeFields || [];
|
|
39
44
|
fillSafeFields(data, err, safeFields);
|
|
40
45
|
|
|
41
46
|
return data;
|
|
42
47
|
};
|
|
43
48
|
|
|
44
|
-
function serializeArrayOfErrors(errors) {
|
|
45
|
-
|
|
46
|
-
for (var ix in errors) {
|
|
47
|
-
var err = errors[ix];
|
|
48
|
-
if (typeof err !== 'object') {
|
|
49
|
-
details.push('' + err);
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
var data = {};
|
|
54
|
-
cloneAllProperties(data, err);
|
|
55
|
-
delete data.statusCode;
|
|
56
|
-
details.push(data);
|
|
57
|
-
}
|
|
58
|
-
|
|
49
|
+
function serializeArrayOfErrors(errors, options) {
|
|
50
|
+
const details = errors.map(e => buildResponseData(e, options));
|
|
59
51
|
return {
|
|
60
|
-
|
|
52
|
+
statusCode: 500,
|
|
61
53
|
message: 'Failed with multiple errors, ' +
|
|
62
54
|
'see `details` for more information.',
|
|
63
55
|
details: details,
|
package/package.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"name": "strong-error-handler",
|
|
3
3
|
"description": "Error handler for use in development and production environments.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "3.0.0",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=6"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"accepts": "^1.3.3",
|
|
21
|
-
"debug": "^
|
|
22
|
-
"ejs": "^2.
|
|
23
|
-
"http-status": "^1.
|
|
21
|
+
"debug": "^3.1.0",
|
|
22
|
+
"ejs": "^2.6.1",
|
|
23
|
+
"http-status": "^1.1.2",
|
|
24
24
|
"js2xmlparser": "^3.0.0",
|
|
25
|
-
"strong-globalize": "^
|
|
25
|
+
"strong-globalize": "^4.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"chai": "^
|
|
29
|
-
"eslint": "^
|
|
30
|
-
"eslint-config-loopback": "^
|
|
31
|
-
"express": "^4.
|
|
32
|
-
"mocha": "^
|
|
33
|
-
"supertest": "^3.
|
|
28
|
+
"chai": "^4.1.2",
|
|
29
|
+
"eslint": "^4.19.1",
|
|
30
|
+
"eslint-config-loopback": "^10.0.0",
|
|
31
|
+
"express": "^4.16.3",
|
|
32
|
+
"mocha": "^5.2.0",
|
|
33
|
+
"supertest": "^3.1.0"
|
|
34
34
|
},
|
|
35
35
|
"browser": {
|
|
36
36
|
"strong-error-handler": false
|