@caviajs/http-exception
v1.0.5
Published
ecosystem for your guinea pig
Downloads
5
Readme
Introduction
This package includes an HttpException
which is used to standardize error responses.
Usage
Installation
npm install @caviajs/http-exception --save
Create an instance
Default reason:
import { HttpException } from '@caviajs/http-exception';
const example = new HttpException(404);
example.getResponse(); // { statusCode: 404, statusMessage: 'Not Found' }
example.getStatus(); // 404
Custom string reason:
import { HttpException } from '@caviajs/http-exception';
const example = new HttpException(404, 'Guinea pig not found');
example.getResponse(); // { statusCode: 404, statusMessage: 'Guinea pig not found' }
example.getStatus(); // 404
Custom object reason:
import { HttpException } from '@caviajs/http-exception';
const example = new HttpException(404, { code: 'GUINEA_PIG_NOT_FOUND' });
example.getResponse(); // { code: 'GUINEA_PIG_NOT_FOUND' }
example.getStatus(); // 404