Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ExtendedErrorFactory<T>

ExtendedErrorFactory

ExtendedErrorFactory is error factory with predefined common errors

Type parameters

Hierarchy

Index

Constructors

constructor

Properties

BaseError

BaseError: HttpBaseError = class HttpBaseError extends BaseError {httpCode: number = 500;}

ConflictError

ConflictError: ConflictError = this.defineErrorClass(class ConflictError extends this.BaseError {httpCode = 409;})

ConflictError

Error raised when there has been conflict

ConnectionError

ConnectionError: ConnectionError = this.defineErrorClass(class ConnectionError extends this.BaseError {httpCode = 504;})

ConnectionError

Error raised when there has been error with a connection

InternalError

InternalError: InternalError = this.defineErrorClass(class InternalError extends this.BaseError {})

InternalError

Error raised when there has been internal error

LogicalError

LogicalError: LogicalError = this.defineErrorClass(class LogicalError extends this.BaseError {httpCode = 422;})

LogicalError

Error raised when there was error in a logic

NotFoundError

NotFoundError: NotFoundError = this.defineErrorClass(class NotFoundError extends this.BaseError {httpCode = 404;})

NotFoundError

Error raised when something is not found

NotImplementedError

NotImplementedError: NotImplementedError = this.defineErrorClass(class NotImplementedError extends this.BaseError {})

NotImplementedError

Error raised when functionality is not implemented

UnauthorizedError

UnauthorizedError: UnauthorizedError = this.defineErrorClass(class UnauthorizedError extends this.BaseError {httpCode = 401;})

UnauthorizedError

Error raised when access has been unauthorized

ValidationError

ValidationError: ValidationError = this.defineErrorClass(class ValidationError extends this.BaseError {httpCode = 400;})

ValidationError

Error raised when there has been error with validation

context

context: Object

Methods

defineErrorClass

  • defineErrorClass<T>(error: T): T
  • Defines a new error class on ErrorFactory

    example

    class MyErrorFactory extends BaseErrorFactory { MyError = this.defineErrorClass( class MyError extends this.BaseError {} ); }

    const factory = new MyErrorFactory();

    throw new factory.MyError('some_error_code');

    Type parameters

    Parameters

    • error: T

    Returns T

withContext

  • withContext<F>(this: F, context?: Object): F
  • Creates new error factory with global error context that is avalible on all errors defined on returned error factory.

    example

    class MyErrorFactory extends BaseErrorFactory { MyError = this.defineErrorClass( class MyError extends this.BaseError {} ); }

    const contextualErrorFactory = new MyErrorFactory().withContext({ userId: '123-123' });

    const error = new contextualErrorFactory.MyError('some_error_code');

    error.context; // {userId: '123-123'}

    Type parameters

    Parameters

    • this: F
    • Default value context: Object = {}

    Returns F

Generated using TypeDoc