@coozzy/error
Advanced tools
Comparing version 1.0.0 to 1.1.0
67
index.js
@@ -1,37 +0,44 @@ | ||
import logger from '@coozzy/logger'; | ||
'use strict'; | ||
class AppError extends Error { | ||
const logger = require('@coozzy/logger'); | ||
static CANCELLED = 1; | ||
static UNKNOWN = 2; | ||
static INVALID_ARGUMENT = 3; | ||
static TIMEOUT = 4; | ||
static NOT_FOUND = 5; | ||
static ALREADY_EXISTS = 6; | ||
static PERMISSION_DENIED = 7; | ||
static RESOURCE_EXHAUSTED = 8; | ||
static FAILED_PRECONDITION = 9; | ||
static ABORTED = 10; | ||
static OUT_OF_RANGE = 11; | ||
static UNIMPLEMENTED = 12; | ||
static INTERNAL = 13; | ||
static UNAVAILABLE = 14; | ||
static DATA_LOSS = 15; | ||
static UNAUTHENTICATED = 16; | ||
/** | ||
* @param {number} code | ||
* @param {string} message | ||
* @constructor | ||
*/ | ||
let AppError = function (code, message) { | ||
Error.captureStackTrace(this, this.constructor); | ||
this.name = this.constructor.name; | ||
this.message = message; | ||
this.code = code; | ||
}; | ||
require('util').inherits(AppError, Error); | ||
module.exports.AppError = AppError; | ||
constructor(code, message) { | ||
super(message); | ||
this.name = this.constructor.name; | ||
this.code = code; | ||
/** | ||
* @type {{RESOURCE_EXHAUSTED: number, ALREADY_EXISTS: number, UNIMPLEMENTED: number, FAILED_PRECONDITION: number, NOT_FOUND: number, OUT_OF_RANGE: number, UNAUTHENTICATED: number, DATA_LOSS: number, INTERNAL: number, UNAVAILABLE: number, UNKNOWN: number, TIMEOUT: number, ABORTED: number, INVALID_ARGUMENT: number, PERMISSION_DENIED: number}} | ||
*/ | ||
let ErrorCode = { | ||
UNKNOWN: 2, | ||
INVALID_ARGUMENT: 3, | ||
TIMEOUT: 4, | ||
NOT_FOUND: 5, | ||
ALREADY_EXISTS: 6, | ||
PERMISSION_DENIED: 7, | ||
RESOURCE_EXHAUSTED: 8, | ||
FAILED_PRECONDITION: 9, | ||
ABORTED: 10, | ||
OUT_OF_RANGE: 11, | ||
UNIMPLEMENTED: 12, | ||
INTERNAL: 13, | ||
UNAVAILABLE: 14, | ||
DATA_LOSS: 15, | ||
UNAUTHENTICATED: 16 | ||
}; | ||
module.exports.ErrorCode = Object.freeze(ErrorCode); | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} | ||
module.exports.AppError = AppError; | ||
/* eslint-disable no-unused-vars */ | ||
// noinspection JSUnusedLocalSymbols | ||
module.exports.httpErrorHandler = (err, req, res, next) => { | ||
module.exports.httpErrorHandler = function (err, req, res, next) { | ||
logger.error(err.message || err.details, err); | ||
@@ -38,0 +45,0 @@ |
{ | ||
"name": "@coozzy/error", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Simplified error throwing and handling in the coozzy environment", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# coozzy-error | ||
**The packages uses ES6 features so be sure to use Babel to transpile it!** | ||
This package can be used to easily create/throw and handle errors in the coozzy environment. It supports internal, HTTP and gRPC error handling. | ||
@@ -6,0 +4,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3662
102
7