Error Handling di Node.js
Contoh Lengkap - Error Middleware
app.use((req, res, next) => {
next(new ApiError("Route tidak ditemukan", 404));
});
app.use((err, req, res, next) => {
const statusCode = err.statusCode || 500;
const message = err.message || "Internal Server Error";
console.error({
error: message,
stack: err.stack,
path: req.path,
});
res.status(statusCode).json({
success: false,
error: message,
});
});