JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q8696F
  • License Unlicense

A handy set of "named" (i.e. in the stack trace) error classes with TypeScript support

Package Exports

  • named-app-errors

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (named-app-errors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm version

named-app-errors

This package exports a set of "named" (i.e. in the stack trace) error classes (extending the Error class) with TypeScript support. The output of these errors provides better DX than normal since the error type's name is included in the message text.

This package includes TypeScript types and provides:

  • A UMD/CJS/AMD bundle (no tree-shaking)
  • ES2015 modules (tree-shaking)

Install

npm install named-app-errors

Usage

import { AppError, GuruMeditationError } from 'named-app-errors'

try {
    throw new GuruMeditationError();
}

catch(e) {
    if(e instanceof AppError)
        console.error(e.message) // ==> "GuruMeditationError"

    else
        throw e;
}

Type Glossary

This library provides the following types:

AppError

AppError(message?: string, fileName?: string, lineNumber?: number)

A generic application error. Direct descendant of Error with the same constructor and no additional functionality. This class is meant to be used as an application-wide base error class, which makes it useful for stuff like instanceof checks in catch blocks (so that we're only handling our application's errors).

import { AppError } from 'named-app-errors'

throw new AppError();

NamedAppError

NamedAppError(name: string, message?: string)

A generic application error that has a name. A message is optional.

import { NamedAppError } from 'named-app-errors'

throw new NamedAppError('MyCustomError');

GuruMeditationError

GuruMeditationError(message?: string)

A generic application error.

import { AppError } GuruMeditationError 'named-app-errors'

throw new GuruMeditationError();

HookError

HookError(message?: string)

A generic application error.

import { HookError } from 'named-app-errors'

throw new HookError();

FetchError

FetchError(res: Response, error?: string)

A generic application error.

import { FetchError } from 'named-app-errors'

throw new FetchError();

NotAuthorizedError

NotAuthorizedError(message?: string)

A generic application error.

import { AppError NotAuthorizedError from 'named-app-errors'

throw new NotAuthorizedError();

NotFoundError

NotFoundError(reference?: T)

A generic application error.

import { NotFoundError } from 'named-app-errors'

throw new NotFoundError();

KeyTypeError

KeyTypeError()

A generic application error.

import { KeyTypeError } from 'named-app-errors'

throw new KeyTypeError();

ValidationError

ValidationError(message?: string)

A generic application error.

import { ValidationError } from 'named-app-errors'

throw new ValidationError();

Represents an object with well-defined NextApiRequest and NextApiResponse properties where generic type T is passed to NextApiResponse<T>.

Specifying T is optional. By default, T = Record<string, unknown>.

import type { NextParamsRR } from '@ergodark/next-types'

export async function addToRequestLog({ req, res }: NextParamsRR) {
    ...
}

Contributing

Issues and pull requests are welcome! In lieu of a formal styleguide, take care to maintain the existing coding style.

Add unit tests for any new or changed functionality (if necessary). Please lint and test your code!

Release History

  • 1.0.x Initial release