flora-errors
Advanced tools
Comparing version 0.6.0 to 0.7.0
169
index.js
'use strict'; | ||
var util = require('util'); | ||
const has = require('has'); | ||
/** | ||
* Base class for Flora errors. | ||
* | ||
* @extends Error | ||
* @constructor | ||
* @param {string} message | ||
*/ | ||
function FloraError(message) { | ||
Error.captureStackTrace(this, this.constructor); | ||
this.name = this.constructor.name; | ||
class FloraError extends Error { | ||
constructor(message, ...args) { | ||
super(message, ...args); | ||
/** | ||
* @type {string} | ||
* @name FloraError#message | ||
* @readonly | ||
*/ | ||
this.message = message; | ||
Error.captureStackTrace(this, this.constructor); | ||
this.name = this.constructor.name; | ||
/** | ||
* @type {number} | ||
* @name FloraError#httpStatusCode | ||
* @readonly | ||
*/ | ||
this.httpStatusCode = 500; // HTTP status for "other errors" | ||
/** | ||
* @type {string} | ||
* @name FloraError#message | ||
* @readonly | ||
*/ | ||
this.message = message; | ||
/** | ||
* @type {number} | ||
* @name FloraError#httpStatusCode | ||
* @readonly | ||
*/ | ||
this.httpStatusCode = 500; // HTTP status for "other errors" | ||
} | ||
} | ||
util.inherits(FloraError, Error); | ||
/** | ||
* @extends FloraError | ||
* @constructor | ||
* @param {string} message | ||
*/ | ||
function RequestError(message) { | ||
FloraError.call(this, message); | ||
this.httpStatusCode = 400; | ||
class RequestError extends FloraError { | ||
constructor(...args) { | ||
super(...args); | ||
this.httpStatusCode = 400; | ||
} | ||
} | ||
util.inherits(RequestError, FloraError); | ||
/** | ||
* @extends FloraError | ||
* @constructor | ||
* @param {string} message | ||
*/ | ||
function AuthenticationError(message) { | ||
FloraError.call(this, message); | ||
this.httpStatusCode = 401; | ||
class AuthenticationError extends FloraError { | ||
constructor(...args) { | ||
super(...args); | ||
this.httpStatusCode = 401; | ||
} | ||
} | ||
util.inherits(AuthenticationError, FloraError); | ||
/** | ||
* @extends FloraError | ||
* @constructor | ||
* @param {string} message | ||
*/ | ||
function AuthorizationError(message) { | ||
FloraError.call(this, message); | ||
this.httpStatusCode = 403; | ||
class AuthorizationError extends FloraError { | ||
constructor(...args) { | ||
super(...args); | ||
this.httpStatusCode = 403; | ||
} | ||
} | ||
util.inherits(AuthorizationError, FloraError); | ||
/** | ||
* @extends FloraError | ||
* @constructor | ||
* @param {string} message | ||
*/ | ||
function NotFoundError(message) { | ||
FloraError.call(this, message); | ||
this.httpStatusCode = 404; | ||
class NotFoundError extends FloraError { | ||
constructor(...args) { | ||
super(...args); | ||
this.httpStatusCode = 404; | ||
} | ||
} | ||
util.inherits(NotFoundError, FloraError); | ||
/** | ||
* @extends FloraError | ||
* @constructor | ||
* @param {string} message | ||
*/ | ||
function ImplementationError(message) { | ||
FloraError.call(this, message); | ||
this.httpStatusCode = 500; | ||
class ImplementationError extends FloraError { | ||
constructor(...args) { | ||
super(...args); | ||
this.httpStatusCode = 500; | ||
} | ||
} | ||
util.inherits(ImplementationError, FloraError); | ||
/** | ||
* @extends FloraError | ||
* @constructor | ||
* @param {string} message | ||
*/ | ||
function DataError(message) { | ||
FloraError.call(this, message); | ||
this.httpStatusCode = 500; | ||
class DataError extends FloraError { | ||
constructor(...args) { | ||
super(...args); | ||
this.httpStatusCode = 500; | ||
} | ||
} | ||
util.inherits(DataError, FloraError); | ||
/** | ||
* @extends FloraError | ||
* @constructor | ||
* @param {string} message | ||
*/ | ||
function ConnectionError(message) { | ||
FloraError.call(this, message); | ||
this.httpStatusCode = 503; | ||
class ConnectionError extends FloraError { | ||
constructor(...args) { | ||
super(...args); | ||
this.httpStatusCode = 503; | ||
} | ||
} | ||
util.inherits(ConnectionError, FloraError); | ||
@@ -117,3 +85,3 @@ /** | ||
function format(err, options) { | ||
var error = {message: 'Internal Server Error'}; | ||
const error = { message: 'Internal Server Error' }; | ||
@@ -131,5 +99,6 @@ options = options || {}; | ||
if (err.info) { | ||
for (var key in err.info) { | ||
if (!error.hasOwnProperty(key) && err.info.hasOwnProperty(key)) error[key] = err.info[key]; | ||
} | ||
Object.keys(err.info).forEach((key) => { | ||
if (!has(error, key) && | ||
has(err.info, key)) error[key] = err.info[key]; | ||
}); | ||
} | ||
@@ -142,11 +111,11 @@ } | ||
module.exports = { | ||
RequestError: RequestError, | ||
AuthenticationError: AuthenticationError, | ||
AuthorizationError: AuthorizationError, | ||
NotFoundError: NotFoundError, | ||
ImplementationError: ImplementationError, | ||
DataError: DataError, | ||
ConnectionError: ConnectionError, | ||
FloraError: FloraError, | ||
format: format | ||
RequestError, | ||
AuthenticationError, | ||
AuthorizationError, | ||
NotFoundError, | ||
ImplementationError, | ||
DataError, | ||
ConnectionError, | ||
FloraError, | ||
format | ||
}; |
{ | ||
"name": "flora-errors", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Error definitions for Flora", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"test": "grunt test", | ||
"lint": "grunt lint" | ||
"lint": "eslint index.js" | ||
}, | ||
@@ -17,6 +17,3 @@ "author": { | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/godmodelabs/flora-errors.git" | ||
}, | ||
"repository": "godmodelabs/flora-errors", | ||
"contributors": [ | ||
@@ -37,18 +34,23 @@ { | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=6" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.4.1", | ||
"eslint": "^2.3.0", | ||
"grunt": "^0.4.5", | ||
"grunt-cli": "^0.1.13", | ||
"eslint": "^3.11.0", | ||
"eslint-config-airbnb-base": "^11.0.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"grunt": "^1.0.1", | ||
"grunt-cli": "^1.2.0", | ||
"grunt-contrib-clean": "^1.0.0", | ||
"grunt-eslint": "^18.00", | ||
"grunt-mocha-istanbul": "^3.0.1", | ||
"grunt-mocha-test": "^0.12.7", | ||
"grunt-mocha-istanbul": "^5.0.1", | ||
"grunt-mocha-test": "^0.13.2", | ||
"istanbul": "^0.4.2", | ||
"load-grunt-tasks": "^3.4.0", | ||
"mocha": "^2.3.4", | ||
"mocha": "^3.0.0", | ||
"mocha-bamboo-reporter": "^1.1.0" | ||
}, | ||
"dependencies": { | ||
"has": "^1.0.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
8424
1
14
142
1
+ Addedhas@^1.0.1
+ Addedhas@1.0.4(transitive)