0.1.5 • Published 3 years ago

@pipehnz/error v0.1.5

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

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);
  }
};