@pipehnz/error

0.1.5 • Public • Published

A simple error builder for Node.JS

🤔 How to use?

In general

If you just want to make your custom error, then by following the following lines of code you can define something like this

const { StatusCodes, withError } = require("@pipehnz/error");

const throwCustomError = withError({
  code: "my_custom_error",
  message: "My custom error",
});

// OR

const throwCustomErrorWithHttpStatus = withError({
  code: "my_custom_error",
  message: "My custom error",
  status: StatusCodes.BAD_REQUEST,
});

Http Module

By default, you will be able to use some of the http errors that come ready out-of-box, i.e.

// Using Http Error's Module

const { throwHttpBadRequest } = require("@pipehnz/error/http");

const getProductById = (request, response, next) => {
  try {
    const { id } = request.params;

    if (!id) {
      throwHttpBadRequest();
    }

    // some code ...
  } catch (error) {
    next(error);
  }
};

Package Sidebar

Install

npm i @pipehnz/error

Weekly Downloads

0

Version

0.1.5

License

MIT

Unpacked Size

3.48 kB

Total Files

9

Last publish

Collaborators

  • pipehnz