Socket
Socket
Sign inDemoInstall

express-errors-handler

Package Overview
Dependencies
66
Maintainers
4
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.9 to 1.4.10

16

main.js

@@ -10,8 +10,20 @@ /*eslint no-unused-vars:0*/

function sendErrorDev (err, req, res, next) {
let error;
if (err instanceof Error) {
error = {
name: err.name,
message: err.message
};
if (err.stack) {
error.stack = err.stack.split('\n')
}
} else {
error = err;
}
if (err.name === fetchres.ReadTimeoutError.name) {
logger.error(err, { event: 'dependencytimeout' });
res && res.status(504).send({ type: 'Bad Gateway', error: err });
res && res.status(504).send({ type: 'Bad Gateway', error: error });
} else {
logger.error(err, { event: 'uncaughterror' });
res && res.status(500).send({ type: 'Uncaught Error', error: err });
res && res.status(500).send({ type: 'Uncaught Error', error: error });
}

@@ -18,0 +30,0 @@ }

2

package.json
{
"name": "express-errors-handler",
"version": "1.4.9",
"version": "1.4.10",
"main": "main.js",

@@ -5,0 +5,0 @@ "repository": {

@@ -40,41 +40,55 @@ 'use strict';

beforeEach(() => sinon.stub(logger, 'error'));
afterEach(() => logger.error.restore())
afterEach(() => logger.error.restore());
it('handle an arbitrary error', function (done) {
request(app)
it('handle an arbitrary error', () => {
return request(app)
.get('/caught-error')
.end((err, res) => {
expect(res.status).to.equal(500);
.expect(500)
.expect(res => {
const body = res.body;
expect(body).to.have.property('type', 'Uncaught Error');
expect(body).to.contain.keys('error');
expect(body.error).to.have.property('name', 'Error');
expect(body.error).to.have.property('message', 'potato');
expect(body.error).to.contain.keys('stack');
expect(body.error.stack[0]).to.equal('Error: potato');
expect(logger.error.calledWith(error, { event: 'uncaughterror' })).to.be.true;
done();
});
});
it('handle backend timeout', function (done) {
request(app)
it('handle backend timeout', () => {
return request(app)
.get('/timeout')
.end((err, res) => {
expect(res.status).to.equal(504);
.expect(504)
.expect(res => {
const body = res.body;
expect(body).to.have.property('type', 'Bad Gateway');
expect(body).to.contain.keys('error');
expect(body.error).to.have.property('name', 'ReadTimeoutError');
expect(logger.error.calledWith(readTimeoutError, { event: 'dependencytimeout' })).to.be.true;
done();
});
});
it('handle backend error with custom response', function (done) {
request(app)
it('handle backend error with custom response', () => {
return request(app)
.get('/bad-response')
.end((err, res) => {
expect(res.status).to.equal(513);
.expect(513)
.expect(() => {
expect(logger.error.calledWith(badServerError, { event: 'uncaughterror' })).to.be.true;
done();
});
});
it('handle non-matching error with default response', function (done) {
request(app)
it('handle non-matching error with default response', () => {
return request(app)
.get('/not-bad-response')
.end((err, res) => {
expect(res.status).to.equal(500);
.expect(500)
.expect(res => {
const body = res.body;
expect(body).to.have.property('type', 'Uncaught Error');
expect(body).to.contain.keys('error');
expect(body.error).to.have.property('name', 'TypeError');
expect(body.error).to.have.property('message', 'next is not a function');
expect(body.error).to.contain.keys('stack');
expect(body.error.stack[0]).to.equal('TypeError: next is not a function');
expect(logger.error.calledWith(error, { event: 'uncaughterror' })).to.be.true;
done();
});

@@ -81,0 +95,0 @@ });

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc