16.13.0 • Published 2 years ago

node-error-hunter v16.13.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Error Middleware for Both Client and Server Side

This package, catches the errors of your code, and it logs them with all necessary info about it such as statusCode, message, url that error come from and etc. After logging, it sends message to you via Telegram. So that you can immediately be awared that there is an error occured in your system. You have to send a token via this middleware to be able to logged. We will provide this token for you when you register our system.

Installation

npm install node-error-hunter

Error Types

The package includes some specific errors. Optionally, users can import and throw this specific errors to the error middleware. Or they can throw their custom error but the error response format must include the properties:

  • status
  • statusText
  • url

Server Side Usage

const  express = require("express");
const {NotFoundError} = require("node-error-hunter/server/errors");  

const  errMidd = require("node-error-hunter/server"); // You need to specify server side when import package

const  app = express();  
app.get("/test", (req, res) => {   
    **throw  new  NotFoundError();**
 })

**app.use(errMidd(yourToken));**
app.listen(4000, () => {});

Client Side Usage

For client side, errors can be thrown in different formats. This packages provides logger for fetch and axios http modules. You need to specify that.

Fetch

const  midd = require("node-error-hunter/fetch");

const  errHunter = new  midd(yourToken)

Axios

const  midd = require("node-error-hunter/axios");

const  errHunter = new  midd(yourToken)