New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@webinmove/kosa

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webinmove/kosa

Custom error class to help handle errors at different level with aligned behaviors

latest
Source
npmnpm
Version
1.1.4
Version published
Maintainers
0
Created
Source

Kosa

Description

Kosa means "error" in Swahili.

This package introduces a managed scoped Error class. The Error Object which is instanciated doesn't have stacktrace on purpose. It is designed to be and stay simple !!!

Here is an exemple:

{
  statusCode: 400,
  message: 'USER_REGISTER_BAD_REQUEST', // Comes from scope & status
  meta: { // Optional - contextual information
    error: '...',
    context: '...',
    details: {
      ...
    },
    validations: [
      {
        field: 'email',
        message: 'missing tld'
      }, 
      {
        field: 'firstname',
        message: 'should start with a capital'
      }
    ]
    ...
  }
}

Usage

Here are the constructor arguments:

  • scope required string
  • statusCode optional number
  • meta optional object with contextual information you might want to provide about the error

Here is how you use it in your code.

const Kosa = require('@webinmove/kosa');

if (!user) {
  throw new Kosa('USER', 404);
}

if (vadlidationErrors.length > 0) {
  throw new Kosa('USER_REGISTER', 400, vadlidationErrors);
}

Valid status code

  • 400 BAD_REQUEST
  • 401 UNAUTHORIZED
  • 403 FORBIDDEN
  • 404 NOT_FOUND
  • 405 METHOD_NOT_ALLOWED
  • 408 REQUEST_TIMEOUT
  • 409 CONFLICT
  • 415 UNSUPPORTED_MEDIA_TYPE
  • 418 TEAPOT
  • 429 TOO_MANY_REQUESTS
  • 500 INTERNAL_SERVER_ERROR (default)

Keywords

error

FAQs

Package last updated on 23 Oct 2024

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