0.3.2 • Published 22 days ago

sendable-error v0.3.2

Weekly downloads
3
License
MIT
Repository
github
Last release
22 days ago

sendable-error · GitHub license npm version

Composable errors to simplify creating useful failure responses for APIs

npm i sendable-error

Note: this package is in early development, use with caution

SendableErrors provide built-in support for:

  • An easy to use builder interface to construct errors
  • A unified way to send your errors as a JSON response
  • Error codes to easily identify error types on the client side
  • Public and private messages & details so your APIs don't leak technical information yet retaining verbose logging
  • Trace IDs allow you to identify specific errors and allows user's to point you in the right direction when they encounter a bug
  • A customizable logger interface

Getting Started

Creating a new error from scratch:

import {SendableError, ErrorCode} from "sendable-error";

const CODE_MISSING_REQUIRED = new ErrorCode("validation/missing-required", "Missing required field", {statusCode: 400});

export const updateUser = (req, res) => {
    if (!req.body.id) {
        return SendableError.of(CODE_MISSING_REQUIRED)
            .message("Missing required field 'id'")
            .details({
                field: "id"
            })
            .build()
            .send(res);
    }
};

In this example if you miss the ID field from the body you shall receive a 400 status code error with the body:

{
  "code": "validation/missing-required",
  "message": "Missing required field 'id'",
  "traceId": "8ab9c56a-90d1-5e71-b67a-d6b725837802",
  "details": {
    "field": "id"
  }
}
0.4.0-alpha.4

22 days ago

0.4.0-alpha.3

1 month ago

0.4.0-alpha.2

2 months ago

0.4.0-alpha.1

2 months ago

0.3.2

2 months ago

0.3.0

6 months ago

0.3.1

6 months ago

0.2.1

10 months ago

0.2.6

8 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.5

8 months ago

0.2.4

10 months ago

0.1.2

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.0-alpha.16

2 years ago

0.1.0-alpha.18

2 years ago

0.1.0-alpha.17

2 years ago

0.1.0-alpha.19

1 year ago

0.1.0

1 year ago

0.1.0-alpha1

2 years ago

0.1.0-alpha2

2 years ago

0.1.0-alpha3

2 years ago

0.1.0-alpha4

2 years ago

0.1.0-alpha5

2 years ago

0.1.0-alpha6

2 years ago

0.1.0-alpha8

2 years ago

0.1.0-alpha9

2 years ago

0.1.0-alpha13

2 years ago

0.1.0-alpha15

2 years ago

0.1.0-alpha10

2 years ago

0.1.0-alpha12

2 years ago

0.1.0-alpha11

2 years ago

0.0.17

3 years ago

0.0.16

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.15

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago