Socket
Socket
Sign inDemoInstall

q3-core-responder

Package Overview
Dependencies
64
Maintainers
1
Versions
261
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    q3-core-responder

Q3 responder handles two responsibilities: (1) assigning HTTP status codes to unhandled exceptions and (2) throwing custom errors in the stack. Within client projects, the first is irrelevant as Q3 registers the functionality via global express middle


Version published
Weekly downloads
67
increased by458.33%
Maintainers
1
Install size
6.05 MB
Created
Weekly downloads
 

Readme

Source

Responder

Q3 responder handles two responsibilities: (1) assigning HTTP status codes to unhandled exceptions and (2) throwing custom errors in the stack. Within client projects, the first is irrelevant as Q3 registers the functionality via global express middleware. However, the second is very common when dealing with custom validation logic.

API

exception

The exception export offers a chainable API for building general and field-level errors. When constructing, the first parameter will correspond to an HTTP status code (see table below).

ErrorCode
BadRequest400
Authentication401
Authorization403
ResourceNotFound404
Conflict409
Gone410
Preprocessing412
Validation422
InternalServer500

Afterwards, you can chain the following methods. You can invoke msg and field in any order but boomerang, log and throw should end your chain.

MethodParamDescription
msgStringThe language key for a message to decorate the HTTP response
fieldString or ObjectThe field-level error to report. If a string, it will duplicate the msg output. If an object, you can provide custom messages and map to multiple fields.
throwA custom error will throw in your stack
boomerangA custom error will return
logA custom error will log to console
Example
const { exception } = require('q3-core-responder');

function doSomething(args = {}) {
  if (args.bad)
    exception('Conflict')
      .msg('custom18nMessageKey')
      .field('name')
      .throw();

  if (args.reallyBad)
    exception('Validation')
      .msg('custom18nMessageKey')
      .field({
        in: 'application', // can be anything
        name: ['field1', 'field2'],
        msg: 'dataNoGood',
      })
      .throw();
}

FAQs

Last updated on 06 Feb 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc