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

create-boom-error

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-boom-error - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

8

CHANGELOG.md

@@ -0,1 +1,9 @@

### 0.3.0 (2020-10-16)
##### New Features
* **codes:**
* attach error codes to the constructor ([a8e69cdb](https://github.com/lob/create-boom-error/commit/a8e69cdb05658dbd76688cf9e48def2716363bb3))
* attach error codes to the constructor ([4b42140d](https://github.com/lob/create-boom-error/commit/4b42140d77dbe414d587247af5b991a68bae9a88))
### 0.2.0 (2020-04-28)

@@ -2,0 +10,0 @@

14

index.js

@@ -10,5 +10,6 @@ 'use strict';

* @param {function | string} message
* @param {string} code
* @returns {new () => Boom<null>}
*/
function createBoomError(name, statusCode, message) {
function createBoomError(name, statusCode, message, code) {
var exports = this;

@@ -18,2 +19,5 @@

this.name = name;
if (code) {
this.code = code;
}

@@ -24,11 +28,11 @@ this.message = undefined;

} else if (typeof message === 'function') {
this.message = message.apply(undefined, arguments);
this.message = message.apply(null, arguments);
}
Boom.boomify(this, { statusCode, });
Boom.boomify(this, { statusCode });
if (message === undefined) {
if (!message) {
Reflect.deleteProperty(this.output.payload, 'message');
}
}
};

@@ -35,0 +39,0 @@ ErrorCtor.prototype = Object.create(Error.prototype);

{
"name": "create-boom-error",
"version": "0.2.0",
"version": "0.3.0",
"description": "Simply create sub-classed Boom errors for Hapi applications.",

@@ -10,3 +10,6 @@ "main": "index.js",

"scripts": {
"test": "mocha test test/index.test.js"
"test": "mocha test test/index.test.js",
"release:major": "changelog -M && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version major && git push origin && git push origin --tags",
"release:minor": "changelog -m && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version minor && git push origin && git push origin --tags",
"release:patch": "changelog -p && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags"
},

@@ -30,2 +33,3 @@ "repository": {

"chai": "^2.1.2",
"generate-changelog": "^1.8.0",
"mocha": "^7.1.0"

@@ -32,0 +36,0 @@ },

@@ -11,3 +11,3 @@ # create-boom-error [![npm version](https://badge.fury.io/js/create-boom-error.svg)](http://badge.fury.io/js/create-boom-error) [![Build Status](https://travis-ci.org/lob/create-boom-error.svg)](https://travis-ci.org/lob/create-boom-error)

### `createBoomError(name, statusCode, [message])`
### `createBoomError(name, statusCode, [message], [code])`

@@ -18,2 +18,3 @@ Creates a Boom error.

- `message` - an optional string or function which returns a string
- `code` - an optional machine-keyable error status string

@@ -25,3 +26,3 @@ ### Create a simple error

var MyError = createBoomError('MyError', 404, 'simple message');
var MyError = createBoomError('MyError', 404, 'simple message', 'not_found');

@@ -28,0 +29,0 @@ var err = new MyError();

@@ -15,2 +15,3 @@ 'use strict';

expect(err.message).to.eql('string message');
expect(err.code).to.not.exist;
expect(err.output).to.eql({

@@ -35,2 +36,3 @@ statusCode: 404,

expect(err.message).to.eql('value is one');
expect(err.code).to.not.exist;
expect(err.output).to.eql({

@@ -52,2 +54,3 @@ statusCode: 422,

expect(err instanceof Error).to.be.true;
expect(err.code).to.not.exist;
expect(err.output).to.eql({

@@ -63,2 +66,19 @@ statusCode: 422,

it('should create a boom error with an optional error code', () => {
const code = 'invalid';
const CodeError = createBoomError('CodeError', 422, null, code);
const err = new CodeError();
expect(err instanceof CodeError).to.be.true;
expect(err instanceof Error).to.be.true;
expect(err.code).to.eql(code);
expect(err.output).to.eql({
statusCode: 422,
payload: {
statusCode: 422,
error: 'Unprocessable Entity'
},
headers: {}
});
});
it('should create a boom string message error on exports', function () {

@@ -65,0 +85,0 @@ var err = new CustomErrors.StringError();

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