Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

strong-error-handler

Package Overview
Dependencies
Maintainers
7
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strong-error-handler - npm Package Compare versions

Comparing version 3.3.0 to 3.4.0

16

CHANGES.md

@@ -0,1 +1,17 @@

2019-10-12, Version 3.4.0
=========================
* chore: js2xmlparser to ^4.0.0 (Miroslav Bajtoš)
* chore: update dev-dependencies (mocha, supertest) (Miroslav Bajtoš)
* chore: update eslint & config to latest (Miroslav Bajtoš)
* chore: update strong-globalize to ^5.0.2 (Miroslav Bajtoš)
* chore: update debug to ^4.1.1 (Miroslav Bajtoš)
* feat: drop support for Node.js 6.x (Miroslav Bajtoš)
2019-09-30, Version 3.3.0

@@ -2,0 +18,0 @@ =========================

4

lib/clone.js

@@ -18,3 +18,3 @@ // Copyright IBM Corp. 2016. All Rights Reserved.

data.message = err.message;
for (var p in err) {
for (const p in err) {
if ((p in data)) continue;

@@ -25,2 +25,2 @@ data[p] = err[p];

data.stack = err.stack;
};
}

@@ -7,8 +7,8 @@ // Copyright IBM Corp. 2016,2018. All Rights Reserved.

'use strict';
var accepts = require('accepts');
var debug = require('debug')('strong-error-handler:http-response');
var sendJson = require('./send-json');
var sendHtml = require('./send-html');
var sendXml = require('./send-xml');
var util = require('util');
const accepts = require('accepts');
const debug = require('debug')('strong-error-handler:http-response');
const sendJson = require('./send-json');
const sendHtml = require('./send-html');
const sendXml = require('./send-xml');
const util = require('util');

@@ -27,3 +27,3 @@ module.exports = negotiateContentProducer;

function negotiateContentProducer(req, logWarning, options) {
var SUPPORTED_TYPES = [
const SUPPORTED_TYPES = [
'application/json', 'json',

@@ -35,3 +35,3 @@ 'text/html', 'html',

options = options || {};
var defaultType = 'json';
let defaultType = 'json';

@@ -58,5 +58,5 @@ // checking if user provided defaultType is supported

// In this case `resolvedContentType` will result as: `text/html` due to the order given
var resolvedContentType = accepts(req).types(SUPPORTED_TYPES);
const resolvedContentType = accepts(req).types(SUPPORTED_TYPES);
debug('Resolved content-type', resolvedContentType);
var contentType = resolvedContentType || defaultType;
let contentType = resolvedContentType || defaultType;

@@ -78,3 +78,3 @@ if (options.negotiateContentType === false) {

// https://github.com/strongloop/strong-remoting/blob/ac3093dcfbb787977ca0229b0f672703859e52e1/lib/http-context.js#L643-L645
var query = req.query || {};
const query = req.query || {};
if (query._format) {

@@ -85,3 +85,3 @@ if (SUPPORTED_TYPES.indexOf(query._format) > -1) {

// format passed through query but not supported
var msg = util.format('Response _format "%s" is not supported' +
const msg = util.format('Response _format "%s" is not supported' +
'used "%s" instead"', query._format, defaultType);

@@ -88,0 +88,0 @@ logWarning(msg);

@@ -8,4 +8,4 @@ // Copyright IBM Corp. 2016,2018. All Rights Reserved.

var cloneAllProperties = require('../lib/clone.js');
var httpStatus = require('http-status');
const cloneAllProperties = require('../lib/clone.js');
const httpStatus = require('http-status');

@@ -48,3 +48,3 @@ module.exports = buildResponseData;

return data;
};
}

@@ -51,0 +51,0 @@ function serializeArrayOfErrors(errors, options) {

@@ -8,10 +8,10 @@ // Copyright IBM Corp. 2016,2018. All Rights Reserved.

var path = require('path');
var SG = require('strong-globalize');
const path = require('path');
const SG = require('strong-globalize');
SG.SetRootDir(path.resolve(__dirname, '..'));
var buildResponseData = require('./data-builder');
var debug = require('debug')('strong-error-handler');
var format = require('util').format;
var logToConsole = require('./logger');
var negotiateContentProducer = require('./content-negotiation');
const buildResponseData = require('./data-builder');
const debug = require('debug')('strong-error-handler');
const format = require('util').format;
const logToConsole = require('./logger');
const negotiateContentProducer = require('./content-negotiation');

@@ -33,3 +33,3 @@ function noop() {

// Log all errors via console.error (enabled by default)
var logError = options.log !== false ? logToConsole : noop;
const logError = options.log !== false ? logToConsole : noop;

@@ -40,3 +40,3 @@ return function strongErrorHandler(err, req, res, next) {

};
};
}

@@ -65,3 +65,3 @@ /**

var data = buildResponseData(err, options);
const data = buildResponseData(err, options);
debug('Response status %s data %j', data.statusCode, data);

@@ -72,3 +72,3 @@

var sendResponse = negotiateContentProducer(req, warn, options);
const sendResponse = negotiateContentProducer(req, warn, options);
sendResponse(res, data);

@@ -80,5 +80,5 @@

}
};
}
exports = module.exports = createStrongErrorHandler;
exports.writeErrorToResponse = writeErrorToResponse;

@@ -8,4 +8,4 @@ // Copyright IBM Corp. 2016. All Rights Reserved.

var format = require('util').format;
var g = require('strong-globalize')();
const format = require('util').format;
const g = require('strong-globalize')();

@@ -19,5 +19,5 @@ module.exports = function logToConsole(req, err) {

var errMsg = g.f('Unhandled array of errors for request %s %s\n',
const errMsg = g.f('Unhandled array of errors for request %s %s\n',
req.method, req.url);
var errors = err.map(formatError).join('\n');
const errors = err.map(formatError).join('\n');
console.error(errMsg, errors);

@@ -24,0 +24,0 @@ };

@@ -7,8 +7,8 @@ // Copyright IBM Corp. 2016. All Rights Reserved.

'use strict';
var ejs = require('ejs');
var fs = require('fs');
var path = require('path');
const ejs = require('ejs');
const fs = require('fs');
const path = require('path');
var assetDir = path.resolve(__dirname, '../views');
var compiledTemplates = {
const assetDir = path.resolve(__dirname, '../views');
const compiledTemplates = {
// loading default template and stylesheet

@@ -21,5 +21,5 @@ default: loadDefaultTemplates(),

function sendHtml(res, data, options) {
var toRender = {options: {}, data: data};
const toRender = {options: {}, data: data};
// TODO: ability to call non-default template functions from options
var body = compiledTemplates.default(toRender);
const body = compiledTemplates.default(toRender);
sendReponse(res, body);

@@ -35,4 +35,4 @@ }

function compileTemplate(filepath) {
var options = {cache: true, filename: filepath};
var fileContent = fs.readFileSync(filepath, 'utf8');
const options = {cache: true, filename: filepath};
const fileContent = fs.readFileSync(filepath, 'utf8');
return ejs.compile(fileContent, options);

@@ -43,3 +43,3 @@ }

function loadDefaultTemplates() {
var defaultTemplate = path.resolve(assetDir, 'default-error.ejs');
const defaultTemplate = path.resolve(assetDir, 'default-error.ejs');
return compileTemplate(defaultTemplate);

@@ -46,0 +46,0 @@ }

@@ -8,8 +8,8 @@ // Copyright IBM Corp. 2016. All Rights Reserved.

var safeStringify = require('fast-safe-stringify');
const safeStringify = require('fast-safe-stringify');
module.exports = function sendJson(res, data) {
var content = safeStringify({error: data});
const content = safeStringify({error: data});
res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.end(content, 'utf-8');
};

@@ -8,8 +8,8 @@ // Copyright IBM Corp. 2017. All Rights Reserved.

var js2xmlparser = require('js2xmlparser');
const js2xmlparser = require('js2xmlparser');
module.exports = function sendXml(res, data) {
var content = js2xmlparser.parse('error', data);
const content = js2xmlparser.parse('error', data);
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
res.end(content, 'utf-8');
};

@@ -5,5 +5,5 @@ {

"license": "MIT",
"version": "3.3.0",
"version": "3.4.0",
"engines": {
"node": ">=6"
"node": ">=8"
},

@@ -23,16 +23,16 @@ "repository": {

"accepts": "^1.3.3",
"debug": "^3.1.0",
"debug": "^4.1.1",
"ejs": "^2.6.1",
"fast-safe-stringify": "^2.0.6",
"http-status": "^1.1.2",
"js2xmlparser": "^3.0.0",
"strong-globalize": "^4.1.0"
"js2xmlparser": "^4.0.0",
"strong-globalize": "^5.0.2"
},
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^4.19.1",
"eslint-config-loopback": "^10.0.0",
"eslint": "^6.5.1",
"eslint-config-loopback": "^13.1.0",
"express": "^4.16.3",
"mocha": "^5.2.0",
"supertest": "^3.1.0"
"mocha": "^6.2.1",
"supertest": "^4.0.2"
},

@@ -39,0 +39,0 @@ "browser": {

@@ -8,9 +8,9 @@ // Copyright IBM Corp. 2016,2018. All Rights Reserved.

var cloneAllProperties = require('../lib/clone.js');
var debug = require('debug')('test');
var expect = require('chai').expect;
var express = require('express');
var strongErrorHandler = require('..');
var supertest = require('supertest');
var util = require('util');
const cloneAllProperties = require('../lib/clone.js');
const debug = require('debug')('test');
const expect = require('chai').expect;
const express = require('express');
const strongErrorHandler = require('..');
const supertest = require('supertest');
const util = require('util');

@@ -31,3 +31,3 @@ describe('strong-error-handler', function() {

givenErrorHandlerForError();
var handler = _requestHandler;
const handler = _requestHandler;
_requestHandler = function(req, res, next) {

@@ -75,3 +75,3 @@ res.end('empty');

givenErrorHandlerForError();
var handler = _requestHandler;
const handler = _requestHandler;
_requestHandler = function(req, res, next) {

@@ -90,3 +90,3 @@ res.statusCode = 507;

context('logging', function() {
var logs;
let logs;

@@ -136,3 +136,3 @@ beforeEach(redirectConsoleError);

var msg = logs[0];
const msg = logs[0];
// the request method

@@ -160,3 +160,3 @@ expect(msg).to.contain('GET');

var msg = logs[0];
const msg = logs[0];
// the request method

@@ -180,3 +180,3 @@ expect(msg).to.contain('GET');

if (err) return done(err);
var msg = logs[0];
const msg = logs[0];
expect(msg).to.contain('STRING ERROR');

@@ -187,7 +187,7 @@ done();

var _consoleError = console.error;
const _consoleError = console.error;
function redirectConsoleError() {
logs = [];
console.error = function() {
var msg = util.format.apply(util, arguments);
const msg = util.format.apply(util, arguments);
logs.push(msg);

@@ -205,3 +205,3 @@ };

it('contains all error properties when debug=true', function(done) {
var error = new ErrorWithProps({
const error = new ErrorWithProps({
message: 'a test error message',

@@ -217,3 +217,3 @@ code: 'MACHINE_READABLE_CODE',

var expectedData = {
const expectedData = {
statusCode: 500,

@@ -235,3 +235,3 @@ message: 'a test error message',

function(done) {
var error = new ErrorWithProps({
const error = new ErrorWithProps({
statusCode: 400,

@@ -247,3 +247,3 @@ message: 'error with code',

var expectedData = {
const expectedData = {
statusCode: 400,

@@ -262,3 +262,3 @@ message: 'error with code',

function(done) {
var error = new ErrorWithProps({
const error = new ErrorWithProps({
statusCode: 500,

@@ -272,3 +272,3 @@ code: 'MACHINE_READABLE_CODE',

var expectedData = {
const expectedData = {
statusCode: 500,

@@ -285,3 +285,3 @@ message: 'Internal Server Error',

function(done) {
var error = new Error('a test error message');
const error = new Error('a test error message');
givenErrorHandlerForError(error, {debug: true});

@@ -291,3 +291,3 @@ requestJson().end(function(err, res) {

expect(res.body).to.have.property('error');
var resError = res.body.error;
const resError = res.body.error;
expect(resError).to.have.property('name', 'Error');

@@ -302,3 +302,3 @@ expect(resError).to.have.property('message',

it('should allow setting safe fields when status=5xx', function(done) {
var error = new ErrorWithProps({
const error = new ErrorWithProps({
name: 'Error',

@@ -324,3 +324,3 @@ safeField: 'SAFE',

it('safe fields falls back to existing data', function(done) {
var error = new ErrorWithProps({
const error = new ErrorWithProps({
name: 'Error',

@@ -343,3 +343,3 @@ isSafe: false,

it('should allow setting safe fields when status=4xx', function(done) {
var error = new ErrorWithProps({
const error = new ErrorWithProps({
name: 'Error',

@@ -366,3 +366,3 @@ statusCode: 422,

it('contains subset of properties when status=4xx', function(done) {
var error = new ErrorWithProps({
const error = new ErrorWithProps({
name: 'ValidationError',

@@ -393,3 +393,3 @@ message: 'The model instance is not valid.',

// Mock an error reported by fs.readFile
var error = new ErrorWithProps({
const error = new ErrorWithProps({
name: 'Error',

@@ -418,3 +418,3 @@ message: 'ENOENT: no such file or directory, open "/etc/passwd"',

it('handles array argument as 500 when debug=false', function(done) {
var errors = [new Error('ERR1'), new Error('ERR2'), 'ERR STRING'];
const errors = [new Error('ERR1'), new Error('ERR2'), 'ERR STRING'];
givenErrorHandlerForError(errors);

@@ -546,5 +546,5 @@

it('handles Error objects containing circular properties', function(done) {
var circularObject = {};
const circularObject = {};
circularObject.recursiveProp = circularObject;
var error = new ErrorWithProps({
const error = new ErrorWithProps({
statusCode: 422,

@@ -576,3 +576,3 @@ message: 'The model instance is not valid.',

it('contains all error properties when debug=true', function(done) {
var error = new ErrorWithProps({
const error = new ErrorWithProps({
message: 'a test error message',

@@ -634,3 +634,3 @@ details: 'some details',

it('contains subset of properties when status=4xx', function(done) {
var error = new ErrorWithProps({
const error = new ErrorWithProps({
name: 'ValidationError',

@@ -646,3 +646,3 @@ message: 'The model instance is not valid.',

expect(res.statusCode).to.eql(422);
var body = res.error.text;
const body = res.error.text;
expect(body).to.match(/some details/);

@@ -658,3 +658,3 @@ expect(body).to.not.match(/sensitive data/);

// Mock an error reported by fs.readFile
var error = new ErrorWithProps({
const error = new ErrorWithProps({
name: 'Error',

@@ -672,3 +672,3 @@ message: 'ENOENT: no such file or directory, open "/etc/passwd"',

expect(res.statusCode).to.eql(500);
var body = res.error.text;
const body = res.error.text;
expect(body).to.not.match(/\/etc\/password/);

@@ -693,3 +693,3 @@ expect(body).to.not.match(/-2/);

it('contains all error properties when debug=true', function(done) {
var error = new ErrorWithProps({
const error = new ErrorWithProps({
message: 'a test error message',

@@ -712,3 +712,3 @@ details: 'some details',

it('contains subset of properties when status=4xx', function(done) {
var error = new ErrorWithProps({
const error = new ErrorWithProps({
name: 'ValidationError',

@@ -724,3 +724,3 @@ message: 'The model instance is not valid.',

expect(res.statusCode).to.eql(422);
var body = res.error.text;
const body = res.error.text;
expect(body).to.match(/<details>some details<\/details>/);

@@ -738,3 +738,3 @@ expect(body).to.not.match(/<extra>sensitive data<\/extra>/);

// Mock an error reported by fs.readFile
var error = new ErrorWithProps({
const error = new ErrorWithProps({
name: 'Error',

@@ -752,3 +752,3 @@ message: 'ENOENT: no such file or directory, open "/etc/passwd"',

expect(res.statusCode).to.eql(500);
var body = res.error.text;
const body = res.error.text;
expect(body).to.not.match(/\/etc\/password/);

@@ -884,3 +884,3 @@ expect(body).to.not.match(/-2/);

it('does not modify "options" argument', function(done) {
var options = {log: false, debug: false};
const options = {log: false, debug: false};
givenErrorHandlerForError(new Error(), options);

@@ -895,3 +895,3 @@ request.get('/').end(function(err) {

var app, _requestHandler, request, server;
let app, _requestHandler, request, server;
function resetRequestHandler() {

@@ -912,3 +912,3 @@ _requestHandler = null;

var handler = strongErrorHandler(options);
const handler = strongErrorHandler(options);
_requestHandler = function(req, res, next) {

@@ -924,3 +924,3 @@ debug('Invoking strong-error-handler');

if (!_requestHandler) {
var msg = 'Error handler middleware was not setup in this test';
const msg = 'Error handler middleware was not setup in this test';
console.error(msg);

@@ -947,3 +947,3 @@ res.statusCode = 500;

server = app.listen(0, function() {
var url = 'http://127.0.0.1:' + this.address().port;
const url = 'http://127.0.0.1:' + this.address().port;
debug('Test server listening on %s', url);

@@ -965,3 +965,3 @@ request = supertest(app);

this.name = props.name || 'ErrorWithProps';
for (var p in props) {
for (const p in props) {
this[p] = props[p];

@@ -978,5 +978,5 @@ }

function getExpectedErrorData(err) {
var data = {};
const data = {};
cloneAllProperties(data, err);
return data;
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc