errorHandler property
dynamic Function(AngelHttpException e, RequestContext req, ResponseContext res)
errorHandler
getter/setter pair
The handler currently configured to run on AngelHttpExceptions.
Implementation
Function(AngelHttpException e, RequestContext req, ResponseContext res)
errorHandler =
(AngelHttpException e, RequestContext req, ResponseContext res) {
if (!req.accepts('text/html', strict: true) &&
(req.accepts('application/json') ||
req.accepts('application/javascript'))) {
res.json(e.toJson());
return;
}
res.contentType = MediaType('text', 'html', {'charset': 'utf8'});
res.statusCode = e.statusCode; // ?? 200;
res.write('<!DOCTYPE html><html><head><title>${e.message}</title>');
res.write('</head><body><h1>${e.message}</h1><ul>');
for (var error in e.errors) {
res.write('<li>$error</li>');
}
res.write('</ul></body></html>');
res.close();
};