Загрузка страницы

Error Handling in #Express with Custom Error Class | 404 | RESTful API using #NodeJS and #MySQL

Error handling in Express is done using middleware. But this middleware has special properties. The error handling middleware are defined in the same way as other middleware functions, except that error-handling functions MUST have four arguments instead of three – err, req, res, next. For example, to send a response on any error, we can use −

Build RESTful APIs with Node.js express and MySQL | Authentication with JWT | In one Video
https://youtu.be/WfCJ3sHnLBM

Converting callbacks to promises | Handle Promises using async/wait | node js tutorial
https://youtu.be/zs6T4Bq9uUs

REST API validation in nodejs
https://youtu.be/F-1GD_F8jHg

download code from github
https://github.com/Tariqu/error-handling-nodejs.git
```
app.use((err, req, res, next) = {
const statusCode = err.statusCode || 500;
res.status(statusCode).json({
success: 0,
message: err.message,
stack: err.stack
})
})
```

Till now we were handling errors in the routes itself. The error handling middleware allows us to separate our error logic and send responses accordingly. The next() method we discussed in middleware takes us to next middleware/route handler.

For error handling, we have the next(err) function. A call to this function skips all middleware and matches us to the next error handler for that route.

Видео Error Handling in #Express with Custom Error Class | 404 | RESTful API using #NodeJS and #MySQL канала Technical Babaji
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
27 сентября 2020 г. 15:03:49
00:11:47
Яндекс.Метрика