Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

error handling in node.js express

1. Operational Errors not bug invalid user input,failed to connect server and database.
2. Programming Errors,bug by the developers like reading properties of undefined,passing a number where object is expected,using await without async.using req.query instead req.body
3. Express use Global error handling Middleware which catch all error. 

//we need to put this code at last,this code run when there is no route match
app.all('*',(req,res,next)=> {
     const err= new Error(`Can't find ${req.originalUrl} on this server!`)
     err.status=404
     err.statusCode=404
    next(err)
})
 
PREVIOUS NEXT
Tagged: #error #handling #express
ADD COMMENT
Topic
Name
1+1 =