berro

Just an Error builder!

Please use therror instead
Last updated a year ago by pateketrueke .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install berro 
SYNC missed versions from official npm registry.

Berro

NPM version travis-ci

Helps to build custom errors based on gRPC error-codes and HTTP status-codes, e.g.

const { buildError, IS_UNIMPLEMENTED } = require('berro');

const MyError = buildError('My.Error', IS_UNIMPLEMENTED, 501);

console.log(new MyError());
/*
{ MyError: 501 Not Implemented - An error has occurred
    at ...
  description: 'An error has occurred',
  identifier: 'Error',
  status: 501,
  type: 'My',
  code: 12 }
*/

The resulting object will contain the following properties:

  • description — Friendly message, or given message at new MyError(...)
  • type and identifier — Taken from first argument as namespace
  • status — The given HTTP status-code (default to 500)
  • code — The given gRPC error-code (default to 13)

Used gRPC codes are:

  • IS_OK — 0
  • IS_CANCELLED — 1
  • IS_UNKNOWN — 2
  • IS_INVALID_ARGUMENT — 3
  • IS_DEADLINE_EXCEEDED — 4
  • IS_NOT_FOUND — 5
  • IS_ALREADY_EXISTS — 6
  • IS_PERMISSION_DENIED — 7
  • IS_UNAUTHENTICATED — 16
  • IS_RESOURCE_EXHAUSTED — 8
  • IS_FAILED_PRECONDITION — 9
  • IS_ABORTED — 10
  • IS_OUT_OF_RANGE — 11
  • IS_UNIMPLEMENTED — 12
  • IS_INTERNAL — 13
  • IS_UNAVAILABLE — 14
  • IS_DATA_LOSS — 15

Current Tags

  • 0.0.2                                ...           latest (a year ago)

2 Versions

  • 0.0.2 [deprecated]           ...           a year ago
  • 0.0.1 [deprecated]           ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |