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

Custom error factory for microservices with http code and "internal" code props

  • 0.6.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-40%
Maintainers
3
Weekly downloads
 
Created
Source

interference2

NPM version NPM downloads styled with prettier Dependencies Status

Custom error factory for microservices with HTTP code and internal type props Edit

Install

npm install interference

Usage

import Interference from 'interference' // or const Interference = require('interference').default

Factory

(message: string, type?: string, details?: any, code?: number): Interference

You can inject custom HTTP codes to map internal type errors to HTTP errors inside your main index.ts/index.js.

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

Keywords

FAQs

Package last updated on 06 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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