10001.0.0 • Published 3 years ago

ts-response v10001.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Usage

import { InternalServerError, responseSuccess, errorHandling } from 'ts-response';

try {
    if (true) {
        throw new InternalServerError('Error');
    }

    responseSuccess(res, {});
} catch (error) {
    errorHandling(res, error);
}

// response: internal server error (500)

response

  • responseOK(res: Response, {data?: Record<string, unknown>})
  • responseOKWithPage(res: Response, pageName: string)
  • responseOKWithFile(res: Response, filePath: string)
  • responseCreated(res: Response, {data?: Record<string, unknown>})
  • responseAccepted(res: Response, {data?: Record<string, unknown>})
  • responseNoContent(res: Response, {data?: Record<string, unknown>})

  • responseBadRequest(res: Response, {errorMessage?: string})

  • responseUnauthorized(res: Response, {errorMessage?: string})
  • responseForbidden(res: Response, {errorMessage?: string})
  • responseConflict(res: Response, {errorMessage?: string})
  • responseInternalServerError(res: Response, {errorMessage?: string})

error

  • BadRequestError(message: string)
  • UnauthorizedError(message: string)
  • ForbiddenError(message: string)
  • NotFoundError(message: string)
  • ConflictError(message: string)
  • InternalServerError(message: string)

handling error

  • errorHandling(res: Response, error: Error)
10001.0.0

3 years ago

10000.0.0

3 years ago

1000.0.0

3 years ago

100.0.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

0.0.0

3 years ago

1.0.0

3 years ago