/HttpStatusSchema

🙅🏾‍♂️ This lib is for abstract errors code from Status Code

Primary LanguageTypeScript

HTTP Status Code

Introduction

This lib is for abstract errors code from Status Code, lib for transcode a string to status code.
Implement errors from HTTP Status Code.

Installation

This is a Node.js module available through the npm registry.

Use npm:

$ npm install http-status-schema

Use yarn:

$ yarn add http-status-schema

Features

  • Declarations Types of name status error for functions

Examples

First you need import the package for your project:

Convert string to status code:

import { selectStatus, StatusName } from 'http-status-schema';

const numberError =  selectStatus('201 Created'); // Convert the name of status to number
// Return 201

Create an interface for the status code:

import { selectStatus, StatusName } from 'http-status-schema';


class AppError {
  status: number;

  message: string;

  constructor(status: StatusName , message: string){
    this.status = selectStatus(status); // Convert the name of status to number
    this.message = message;
  }
}

This project is under the MIT license. See the LICENSE file for more details.