Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

express typescript error handling

import express, { NextFunction, ErrorRequestHandler } from 'express'

const app = express()
app.use(<ErrorRequestHandler>function(err, req, res, next: NextFunction) {
  res.status(err.status ?? 500)
  res.json({
    success: false,
    error: 'Internal error occured'
  })
  next(err)
})
 
PREVIOUS NEXT
Tagged: #express #typescript #error #handling
ADD COMMENT
Topic
Name
8+4 =