Register an exception renderer through withExceptions() in bootstrap/app.js. Use HttpException for errors whose status and message may be returned to clients. Keep APP_DEBUG=false in production so internal exceptions become a generic 500 response, and log failures without recording secrets.
Examples
import { HttpException } from '../framework/Foundation/Exceptions/HttpException.js';
throw new HttpException(404, 'Post tidak ditemukan.');
.withExceptions((exceptions) => {
exceptions.render((error, request, response) => response.json({
message: error.status && error.status < 500
? error.message
: (process.env.APP_DEBUG === 'true' ? error.message : 'Server Error'),
...(error.details ? { errors: error.details } : {}),
}, error.status ?? 500));
})
exceptions.render(async (error, request, response) => {
await app.make('log').error(error.message, {
method: request.method,
path: request.path,
});
return response.json({ message: 'Server Error' }, error.status ?? 500);
});