make404 method
Makes Response for 404 error
Respects 'accept' request header and returns corresponding Response
Implementation
Response make404(Context ctx) {
final String accept = ctx.req.headers.value(HttpHeaders.acceptHeader) ?? '';
final List<String> acceptList = accept.split(',');
if (acceptList.contains('text/html')) {
return Response(
body: _write404Html(ctx),
statusCode: HttpStatus.notFound,
mimeType: MimeTypes.html);
} else if (acceptList.contains('application/json') ||
acceptList.contains('text/json')) {
return Response.json({
'Path': ctx.path,
'Method': ctx.method,
'Message': 'Not found!',
}, statusCode: HttpStatus.notFound);
} /* TODO else if (acceptList.contains('application/xml')) {
return Response.xml({
'Path': ctx.path,
'Method': ctx.method,
'Message': 'Not found!',
}, statusCode: HttpStatus.NOT_FOUND);
return;
} */
else {
return Response(body: _write404Html(ctx), statusCode: HttpStatus.notFound)
..headers.contentType = ContentType.html;
}
}