0.1.8 • Published 2 years ago

express-error-handle v0.1.8

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

express-error-handle

A graceful error handle for Express applications. This also patches a DOS exploit where users can manually trigger bad request errors that shut down your app.

Installation

npm i --save express-error-handle

Express express-error-handle

//If the import statement doesn't work, use require module
const {errorLog,errorHandlerNotify} = require("express-error-handle") //use require
const express = require('express');

const app = express()
const port = process.env.PORT || 5000;

app.get('/a-typical-route',async function(req, res, next) {
try{

//your code here

}
catch(error){
next(error)
}

});


app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})

//handling error using at the end of last routes
//app.use(errorLog);  //optional
app.use(errorHandlerNotify); //required

Supported environment variables

//mongoose default model error handle
//js example


const mongoose,{Schema} = require('mongoose')
const breakfastSchema = new Schema({
  eggs: {
    type: Number,
    min: [6, 'Too few eggs'],
    max: 12
  },
  bacon: {
    type: Number,
    required: [true, 'Why no bacon?']
  },
  drink: {
    type: String,
    enum: ['Coffee', 'Tea'],
  },
  userId:{
    type: Schema.Types.ObjectId,
    ref: 'User'
}

}, { timestamps: true });
const Breakfast = mongoose.model('Breakfast', breakfastSchema);
export default Breakfast;
//mongoose default model error handle
//ts example

import { Document, Schema, model, Types } from 'mongoose';


export interface IBreakfastSchema extends Document {
    eggs: number,
    bacon: Types.ObjectId,
    drink:string,
    userId?:Types.ObjectId,
    createdAt?: Date,
    updatedAt?: Date,
}
export enum drinkEnum{
    coffee="coffee",
    tea="tea",
}
const breakfastSchema = new Schema<IBreakfastSchema>({
  eggs: {
    type: Number,
    min: [6, 'Too few eggs'],
    max: 12
  },
  bacon: {
    type: Number,
    required: [true, 'Why no bacon?']
  },
  drink: {
    type: String,
    enum: ['coffee', 'tea'],
    enum: Object.values(drinkEnum)
  }
  userId:{
    type: Schema.Types.ObjectId, ref: 'User',
  }
}, { timestamps: true });
const Breakfast =  model<IBreakfastSchema>("Breakfast", breakfastSchema);
export default Breakfast;
1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.10

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.0.6

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

0.1.4

2 years ago

0.0.5

2 years ago

0.1.3

2 years ago

0.0.4

2 years ago

0.1.5

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.0

2 years ago