Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@atlas-engine/error_provider

Package Overview
Dependencies
Maintainers
4
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atlas-engine/error_provider

Contains a set of technical errors that our protocal adapters can handle.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

ErrorProvider

A technical error provider.

The errors are based on HTTP, but can be used anywhere else as well. This is also the set of errors that the AtlasEngine uses internally.

Usage

Installation:

npm install --save @atlas-engine/error_provider

Usage in NodeJS:

const ERRORNAME = require('@atlas-engine/error_provider').ERRORNAME;
// or
const {ERRORNAME1, ERRORNAME2, ERRORNAME3} = require('@atlas-engine/error_provider');

const error = new ERRORNAME('fancy error message');

Usage in TypeScript:

import * as Errors from '@atlas-engine/error_provider';
// or
import {ERRORNAME1, ERRORNAME2, ERRORNAME3} from '@atlas-engine/error_provider';

const error = new Errors.ERRORNAME('fancy error message');
const anotherError = new ERRORNAME1('fancy error message');

Where ERRORNAME is the error you want to import.

All errors from this package have the isAtlasEngineError-property, so that they can be easily recognized as such.

Serialization and Deserialization

There are two ways to serialize/deserialize the errors:

Direct serialization

Serialization:

Each error has a serialize function which will create a string representation of the error object.

For example:

import {InternalServerError} from '@atlas-engine/error_provider';

const error = new InternalServerError('error!');
const serializedError = error.serialize();

Deserialization:

The BaseError class provides a static deserialize function, which accepts a string argument. It tries to parse the string into a corresponding AtlasEngine error and returns the result.

For example:

import {BaseError} from '@atlas-engine/error_provider';

const serializedError = '{"errorClassName":"InternalServerError","code":500,"message":"Process was terminated!","callStack":"InternalServerError: Process was terminated!\n    at <InsertStackHere>"}';
const error = BaseError.deserialize();

Note: The function will throw an error, if the given string does not properly represent an AtlasEngine error!

Serializer functions

We also provide a global serialize and deserialize function, which works independently from any internal errors.

Unlike the serializer functions attached to BaseError, these functions are also able to handle base Error objects and even plain JSONs.

Example:

import {BaseError, deserializeError, serializeError} from '@atlas-engine/error_provider';

const internalServerError = new InternalServerError('error!');
const basicError = new Error('error!');
const untypedError = {message: 'Oh no, where did my type info go!?', code: 666};

// Serializing errors
const serializedInternalServerError = serializeError(internalServerError);
const serializedBasicError = serializeError(basicError);
const serializedUntypedError = serializeError(untypedError);

// Deserializing errors
// The results should match the errors declared above
const deserializedInternalServerError = deserializeError(serializedInternalServerError);
const deserializedBasicError = deserializeError(serializedBasicError);
const deserializedUntypedError = deserializeError(serializedUntypedError);

Use these, if you cannot be entirely certain that an error will be from @atlas-engine/error_provider.

A note on @essential-projects/errors_ts

Since this package is the continuation of @essential-projects/errors_ts, the deserializeError and serializeError functions are able to handle errors from that package as well.

Test

You can run the tests by simply calling:

npm test

Error Codes

The Errors are mostly based on HTTP status codes. Every Error, except for the BaseError extends BaseError, which in turn extends Error.

NameCode
BaseError
Information Errors1xx
ContinueError100
SwitchingProtocolsError101
ProcessingError102
Redirect Errors3xx
MultipleChoicesError300
MovedError301
FoundError302
SeeOtherError303
NotModifiedError304
UseProxyError305
TemporaryRedirectError307
PermanentRedirectError308
Client Errors4xx
BadRequestError400
UnauthorizedError401
PaymentRequiredError402
ForbiddenError403
NotFoundError404
MethodNotAllowedError405
NotAcceptableError406
ProxyAuthenticationRequiredError407
RequestTimeoutError408
ConflictError409
GoneError410
LengthRequiredError411
PreconditionFailedError412
RequestTooLargeError413
URLTooLongError414
UnsupportedMediaTypeError415
RequestedRangeNotSatisfiableError416
ExpectationFailedError417
ImATeapotError418
PolicyNotFulfilledError420
MisdirectredRequestError421
UnprocessableEntityError422
LockedError423
FailedDependencyError424
UpgradeRequiredError426
PreconditionRequiredError428
TooManyRequestsError429
RequestHeaderTooLargeError431
UnavaliableForLegalReasonsError451
Server Errors5xx
InternalServerError500
NotImplementedError501
BadGatewayError502
ServiceUnavaliableError503
GatewayTimeoutError504
VersionNotSupportedError505
InsufficientStorageError507
LoopDetectedError508
BandwithLimitExceededError509
NetworkAuthenticationRequiredError511

FAQs

Package last updated on 12 Dec 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc