strong-error-handler 2.3.0 → 3.1.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 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,33 @@
1
+ 2018-07-17, Version 3.1.0
2
+ =========================
3
+
4
+ * [WebFM] cs/pl/ru translation (candytangnb)
5
+
6
+
7
+ 2018-06-11, Version 3.0.0
8
+ =========================
9
+
10
+ * Allow safeFields to work with arrays (shimks)
11
+
12
+ * run lint (shimks)
13
+
14
+ * drop node 4 from travis and update dependencies (shimks)
15
+
16
+
17
+ 2018-03-05, Version 2.3.2
18
+ =========================
19
+
20
+ * Undefined safeFields revert to data #71 (Zak Barbuto)
21
+
22
+
23
+ 2018-01-25, Version 2.3.1
24
+ =========================
25
+
26
+ * Escape strings in HTML output (XSS fix) (Zachery Metcalf)
27
+
28
+ * Update LICENSE.md (Diana Lau)
29
+
30
+
1
31
  2017-10-13, Version 2.3.0
2
32
  =========================
3
33
 
package/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) IBM Corp. 2016. All Rights Reserved.
1
+ Copyright (c) IBM Corp. 2016,2017. All Rights Reserved.
2
2
  Node module: strong-error-handler
3
3
  This project is licensed under the MIT License, full text below.
4
4
 
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
@@ -0,0 +1,5 @@
1
+ {
2
+ "85312d2b987e2e44001db3d6963a1364": "Neošetřené pole chyb pro požadavek {0} {1}\n",
3
+ "adcbd4c562b19f45fb5d3427619646d5": "Neošetřená chyba pro požadavek {0} {1}: {2}"
4
+ }
5
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "85312d2b987e2e44001db3d6963a1364": "Nieobsługiwana tablica błędów dla żądania {0} {1}\n",
3
+ "adcbd4c562b19f45fb5d3427619646d5": "Nieobsługiwany błąd dla żądania {0} {1}: {2}"
4
+ }
5
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "85312d2b987e2e44001db3d6963a1364": "Необработанный массив ошибок для запроса {0} {1}\n",
3
+ "adcbd4c562b19f45fb5d3427619646d5": "Необработанная ошибка для запроса {0} {1}: {2}"
4
+ }
5
+
@@ -64,7 +64,7 @@ function negotiateContentProducer(req, logWarning, options) {
64
64
  } else {
65
65
  debug('contentType: `%s` is not supported, ' +
66
66
  'falling back to contentType: `%s`',
67
- options.defaultType, contentType);
67
+ options.defaultType, contentType);
68
68
  }
69
69
  }
70
70
 
@@ -8,16 +8,18 @@
8
8
  var cloneAllProperties = require('../lib/clone.js');
9
9
  var httpStatus = require('http-status');
10
10
 
11
- module.exports = function buildResponseData(err, options) {
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
- var isDebugMode = options.debug;
16
+ const isDebugMode = options.debug;
15
17
 
16
- if (Array.isArray(err) && isDebugMode) {
17
- err = serializeArrayOfErrors(err);
18
+ if (Array.isArray(err)) {
19
+ return serializeArrayOfErrors(err, options);
18
20
  }
19
21
 
20
- var data = Object.create(null);
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
- } else if (data.statusCode >= 400 && data.statusCode <= 499) {
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
- var safeFields = options.safeFields || [];
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
- var details = [];
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
- name: 'ArrayOfErrors',
52
+ statusCode: 500,
61
53
  message: 'Failed with multiple errors, ' +
62
54
  'see `details` for more information.',
63
55
  details: details,
@@ -91,6 +83,8 @@ function fillSafeFields(data, err, safeFields) {
91
83
  }
92
84
 
93
85
  safeFields.forEach(function(field) {
94
- data[field] = err[field];
86
+ if (err[field] !== undefined) {
87
+ data[field] = err[field];
88
+ }
95
89
  });
96
90
  }
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": "2.3.0",
5
+ "version": "3.1.0",
6
6
  "engines": {
7
- "node": ">=4"
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": "^2.2.0",
22
- "ejs": "^2.4.2",
23
- "http-status": "^1.0.0",
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": "^3.1.0"
25
+ "strong-globalize": "^4.1.0"
26
26
  },
27
27
  "devDependencies": {
28
- "chai": "^3.5.0",
29
- "eslint": "^3.14.1",
30
- "eslint-config-loopback": "^8.0.0",
31
- "express": "^4.13.4",
32
- "mocha": "^3.2.0",
33
- "supertest": "^3.0.0"
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
@@ -1,19 +1,19 @@
1
1
  <html>
2
2
  <head>
3
3
  <meta charset='utf-8'>
4
- <title><%- data.name || data.message %></title>
4
+ <title><%= data.name || data.message %></title>
5
5
  <style><%- include style.css %></style>
6
6
  </head>
7
7
  <body>
8
8
  <div id="wrapper">
9
- <h1><%- data.name %></h1>
10
- <h2><em><%- data.statusCode %></em> <%- data.message %></h2>
9
+ <h1><%= data.name %></h1>
10
+ <h2><em><%= data.statusCode %></em> <%= data.message %></h2>
11
11
  <%
12
12
  // display all the non-standard properties
13
13
  var standardProps = ['name', 'statusCode', 'message', 'stack'];
14
14
  for (var prop in data) {
15
15
  if (standardProps.indexOf(prop) == -1 && data[prop]) { %>
16
- <div><b><%- prop %></b>: <%- data[prop] %></div>
16
+ <div><b><%= prop %></b>: <%= data[prop] %></div>
17
17
  <% }
18
18
  }
19
19
  if (data.stack) { %>