# Jaypie Errors

JSON:API-complaint errors for API Gateways

## Installation

``` bash
npm --save install @cardx/jaypie-errors

npm --prefix src --save install @cardx/jaypie-errors
```

## Usage

``` javascript
import { BadRequestError, formatError, MultiError } from "@cardx/jaypie-errors";

try {
  // Errors are instances of JsonApiHttpError
  throw BadRequestError("Transaction must contain `payment` object");
  throw BadRequestError(); // = The request was incomplete or not properly formatted

  // Multiple errors can be thrown:
  throw MultiError([error1, error2]);
  // MultiError figures out the right response code

} catch (error) {
  // formatError():
  // - throws non-JsonApiHttpError objects out
  // - returns an API Gateway response
  return formatError(error)
}
```

## Errors

### Standard HTTP

* BadGatewayError (`502`)
* BadRequestError (`400`)
* ForbiddenError (`403`)
* GatewayTimeoutError (`504`)
* GoneError (`410`)
* InternalError (`500`)
* MethodNotAllowedError (`405`)
* NotFoundError (`404`)
* TeapotError (`418`)
* UnavailableError (`503`)

### Extensions

* ConfigurationError (`500 Internal Error`)
* DatabaseError (`502 Bad Gateway`)
* DynamoError (`502 Bad Gateway`)
* MultiError (varies)
* RejectedError (`403 Forbidden`)
* StoreError (`502 Bad Gateway`)
* UnreachableCodeError (`500 Internal Error`, also logs warning)

## Changelog

* 1.0.0: A production-worthy release
* 1.1.0: Exports GoneError, MethodNotAllowedError, UnavailableError
* 1.2.0: Adds ConfigurationError
* 1.3.0: Adds StoreError, DynamoError
* 1.4.0: Adds RejectedError

## License

© CardX. All rights reserved.
