@salable/errors
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

CI Checks  License Checker  Release 

Salable Errors

The Salable Errors allows you to properly return HTTPException classes for specific error messages in response to HTTP requests to improve error handling in an application.

Getting Started


Installation

with npm

npm install @salable/errors

with yarn

yarn add @salable/errors

Using HTTPClientException - client errors

With description

import {HTTPClientException} from '@salable/errors';
const errorPayload = {
  description:
    'Your changes were saved, but we could not connect your account due to a technical issue on our end. Please try connecting again.',
};
throw new HTTPClientException('NOT_FOUND', 'Unable to connect to account', errorPayload);
// Expected return
{
  statusCode: 404;
  message: 'Unable to connect to account';
  description: 'Your changes were saved, but we could not connect your account due to a technical issue on our end. Please try connecting again.';
}

With NO description

import {HTTPClientException} from '@salable/errors';
throw new HTTPClientException('NOT_FOUND', 'Unable to connect to account');
// Expected return
{
  statusCode: 404;
  message: 'Unable to connect to account';
  description: undefined;
}

Using HTTPServerException - Server Errors

With description

import {HTTPServerException} from '@salable/errors';
const errorPayload = {
  description:
    'No changes were made, but we could not connect your account due to a technical issue on our end. Please try connecting again.',
};
throw new HTTPServerException('INTERNAL_SERVER_ERROR', 'Unable to connect to network', errorPayload);
// Expected return
{
  statusCode: 500;
  message: 'Unable to connect to account';
  description: 'No changes were made, but we could not connect your account due to a technical issue on our end. Please try connecting again.';
}

With NO description

import {HTTPServerException} from '@salable/errors';
throw new HTTPServerException('INTERNAL_SERVER_ERROR', 'Unable to connect to network');
// Expected return
{
  statusCode: 500;
  message: 'Unable to connect to account';
  description: undefined;
}

Package Sidebar

Install

npm i @salable/errors

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

29 kB

Total Files

36

Last publish

Collaborators

  • orderandchaos_at_work
  • salableapp
  • adaptajay
  • adaptaconer
  • joshokoro
  • sasankg