1.0.5 • Published 6 months ago

@caviajs/http-exception v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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
1.0.5

6 months ago

1.0.2

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago