2.1.0 • Published 6 days ago

@pallad/common-errors v2.1.0

Weekly downloads
7
License
MIT
Repository
github
Last release
6 days ago

CircleCI npm version Coverage Status

License: MIT

Small set of commonly used errors. Carefully designed and battle tested so you don't need to do it.

Installation

npm install @pallad/common-errors

Common api

All errors assume that code property might be set for an error. code is used to uniquely specify what error is being thrown.

Errors

ApplicationError

The most common kind of error. Should be used only if other type of errors do not fit.

import {ApplicationError} from "@pallad/common-errors";

function publishArticle(id: string) {
    const article = findById(id);
    if (article?.status === 'published') {
        throw new ApplicationError('Cannot publish article that is already published');
    }
}

AuthenticationError

Indicates lack of ability to verify who is the participant performing an operation

import {AuthenticationError} from '@pallad/common-errors';

function activateAccount(token: string) {
    if (!verifyToken(token)) {
        throw new AuthenticationError('Invalid token');
    }
}

AuthorizationError

Indicates lack of certain permissions to perform an operation

import {AuthorizationError} from '@pallad/common-errors';

function deleteArticle(participant: Participant, id: string) {
    const article = findById(id);
    if (!hasPermission(article, participant)) {
        throw new AuthorizationError('Invalid token');
    }
}

// TODO

2.1.0

6 days ago

2.0.0

1 year ago

1.5.2

2 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago