4 min read

Error Handler E2

A failed request routed into an error handler while valid requests continue.

Error Handler E2

Build Status npm version 

This package will help you to handle errors, and logging errors with nice style for debugging, and you can use handleHttpError middleware

you can support us with a little, but this become more for us.

Getting Start

You need download package in your project and import any function you need

Installing && Using

    npm install npm i error-handler-e2
    //or
    yarn add error-handler-e2

    const ErrorHandlerrE2 = require("error-handler-e2");
    //or
    import ErrorHandlerrE2 from "error-handler-e2";

Examples

Using Functions

  1. create custom error
    const { createCustomError } = require("error-handler-e2").functions;

    //params createCustomError({message: String, error: ErrorObj, [options]})
    const myError = createCustomError({
      message = "Testing Error message",
      error = {},
    });

  1. create Http Error
    const { createHttpError } = require("error-handler-e2").functions;

    //params createHttpError({message: String, statusCode: Number, [options]})
    const httpError = createHttpError({
         message = "This is message",
        statusCode = 404,
    })
  1. Logging Errors
    const { createCustomError,createHttpError ,logErrors }
            = require("error-handler-e2").functions;

    //params createHttpError({message: String, statusCode: Number, [options]})
    const httpError = createHttpError({
         message = "This is message",
        statusCode = 404,
    })

    //params createCustomError({message: String, error: ErrorObj, [options]})
    const myError = createCustomError({
      message = "Testing Error message",
      error = {},
    });

    logErrors({
        error: httpError,
        file: "index.js",
        path: `${__dirname}/${__filename}`,
    });
    logErrors({
        error: myError,
        file: "index.js",
        path: `${__dirname}/${__filename}`,
    });

Using Middlewares

    const { handleHttpError } = require('error-handler-e2).middlwares;
    const { createHttpError } = require('error-handler-e2).functions;

    //params createHttpError({message: String, statusCode: Number, [options]})
    const httpError = createHttpError({
         message = "This is message",
        statusCode = 404,
    });

    //you need throw httpError, when catch error
    throw httpError;

    //after your routes, using handle error middleware
    app.use(handleHttpError());

Authors

Milad

  • Engineering

    Encrypt By RSA Algorithm

    RSA is a public-key cryptosystem that is widely used for secure data transmission. It is also one of the oldest. The acronym RSA comes from the surnames of Ron Rivest.

    2 min read ↗
  • Engineering

    De Duplicated

    This is package for deleting the duplicated elements in array, there are contain two methods, first method called simpleArray, this method deduplicated the…

    4 min read ↗
  • Engineering

    Memoz

    Memoz is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported, Strings, Lists, Sets, Sorted Sets, Hashes, Streams, HyperLogLogs, Bitmaps.

    3 min read ↗