New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

interference

Package Overview
Dependencies
Maintainers
3
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interference - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

19

lib/index.d.ts

@@ -1,15 +0,16 @@

interface Interference {
interface Options {
message: string;
type: string;
statusCode: number;
details: any;
message: string;
details?: any;
statusCode?: number;
}
export declare class InterferenceError extends Error implements Interference {
export declare class Interference extends Error {
type: string;
statusCode: number;
statusCode?: number;
details: any;
message: string;
constructor(message: string, type?: string, details?: any, code?: number);
constructor({ message, type, details, statusCode }: Options);
}
declare const Interference: (message: string, type?: string | undefined, details?: any, code?: number | undefined) => Interference;
export default Interference;
export declare function isInterference(value: any): value is Interference;
export default function InterferenceFactory({ message, type, details, statusCode, }: Options): Interference;
export {};
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.InterferenceError = void 0;
var InterferenceError = (function (_super) {
__extends(InterferenceError, _super);
function InterferenceError(message, type, details, code) {
if (type === void 0) { type = 'GENERIC_ERROR'; }
if (details === void 0) { details = {}; }
var _this = _super.call(this, message) || this;
Object.setPrototypeOf(_this, InterferenceError.prototype);
Object.defineProperty(_this, 'message', {
exports.isInterference = exports.Interference = void 0;
const symInterference = Symbol.for('interference');
class Interference extends Error {
constructor({ message, type, details = {}, statusCode }) {
super(message);
Object.setPrototypeOf(this, Interference.prototype);
Object.defineProperty(this, symInterference, { value: true });
Object.defineProperty(this, 'message', {
configurable: true,

@@ -30,16 +16,16 @@ enumerable: false,

});
Object.defineProperty(_this, 'name', {
Object.defineProperty(this, 'name', {
configurable: true,
enumerable: false,
value: _this.constructor.name,
value: this.constructor.name,
writable: true,
});
_this.type = type;
_this.details = details;
_this.statusCode = code || 500;
this.type = type;
this.details = details;
this.statusCode = statusCode;
if (Error.hasOwnProperty('captureStackTrace')) {
Error.captureStackTrace(_this, _this.constructor);
return _this;
Error.captureStackTrace(this, this.constructor);
return;
}
Object.defineProperty(_this, 'stack', {
Object.defineProperty(this, 'stack', {
configurable: true,

@@ -50,11 +36,13 @@ enumerable: false,

});
return _this;
}
return InterferenceError;
}(Error));
exports.InterferenceError = InterferenceError;
var Interference = function (message, type, details, code) {
return new InterferenceError(message, type, details, code);
};
exports.default = Interference;
}
exports.Interference = Interference;
function isInterference(value) {
return typeof value === 'object' && value !== null ? value[symInterference] === true : false;
}
exports.isInterference = isInterference;
function InterferenceFactory({ message, type, details, statusCode, }) {
return new Interference({ message, type, details, statusCode });
}
exports.default = InterferenceFactory;
//# sourceMappingURL=index.js.map
{
"name": "interference",
"version": "1.0.0",
"version": "2.0.0",
"description": "Custom error factory for microservices with http code and \"internal\" code props",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -26,3 +26,9 @@ <div align="center">

```javascript
import Interference from 'interference' // or const Interference = require('interference').default
import Interference, { isInterference } from 'interference'
const err = Interference('Good news everyone', 'FUTURAMA')
if (isInterference(err) && err.type === 'FUTURAMA') {
console.log('We have a special delivery today')
}
```

@@ -35,32 +41,3 @@

You can inject custom HTTP codes to map internal type errors to HTTP errors inside your main index.ts/index.js.
```javascript
InjectCodes({
INVALID_OBJECT_ID: 400,
MISSING_OBJECT_ID: 400,
EMPTY_DOCUMENT: 400,
DOCUMENT_VALIDATION_ERROR: 400,
MISSING_UNIQUE_KEY: 400,
MISSING_AUTH_DATA: 400,
CREDENTIALS_NOT_VALID: 400,
MISSING_MANDATORY_PRAMETER: 400,
TOKEN_NOT_VALID: 401,
DOCUMENT_NOT_FOUND: 404,
INCOMPATIBLE_CHANGE_STATUS: 409,
DUPLICATED_DOCUMENT: 409,
REMOTE_UNREACHABLE: 503,
GENERIC_ERROR: 500,
})
```
Then if you create a new error `const error = Interference('Empty document', 'EMPTY_DOCUMENT', { dupe: '4350394' })` it you will be mapped to 400 HTTP error inside `error.statutsCode`.
`InjectCodes` must be called only once inside your project since it will set internal httpCodes var, that will be used for all future Interference instance.
### Referenct to < es6 target
[Extending built-ins Error](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work])

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