Error HTML rendering
This commit is contained in:
parent
24fc679ed8
commit
0a7a0a587d
2 changed files with 26 additions and 12 deletions
|
@ -41,7 +41,8 @@ class Angel extends Routable {
|
||||||
this.httpServer = server;
|
this.httpServer = server;
|
||||||
|
|
||||||
server.listen((HttpRequest request) async {
|
server.listen((HttpRequest request) async {
|
||||||
String req_url = request.uri.toString().replaceAll(new RegExp(r'\/+$'), '');
|
String req_url = request.uri.toString().replaceAll(
|
||||||
|
new RegExp(r'\/+$'), '');
|
||||||
if (req_url.isEmpty)
|
if (req_url.isEmpty)
|
||||||
req_url = '/';
|
req_url = '/';
|
||||||
RequestContext req = await RequestContext.from(request, {}, this, null);
|
RequestContext req = await RequestContext.from(request, {}, this, null);
|
||||||
|
@ -57,16 +58,16 @@ class Angel extends Routable {
|
||||||
if (e is AngelHttpException) {
|
if (e is AngelHttpException) {
|
||||||
// Special handling for AngelHttpExceptions :)
|
// Special handling for AngelHttpExceptions :)
|
||||||
try {
|
try {
|
||||||
String accept = request.headers.value(HttpHeaders.ACCEPT) ?? "*/*";
|
String accept = request.headers.value(HttpHeaders.ACCEPT);
|
||||||
if (accept == "*/*" ||
|
if (accept == "*/*" ||
|
||||||
accept.contains("application/json") ||
|
accept.contains("application/json") ||
|
||||||
accept.contains("application/javascript")) {
|
accept.contains("application/javascript")) {
|
||||||
res.json(e.toMap());
|
res.json(e.toMap());
|
||||||
} else {
|
} else {
|
||||||
await _applyHandler(_errorHandler, req, res);
|
await _applyHandler(_errorHandler, req, res);
|
||||||
|
_finalizeResponse(request, res);
|
||||||
}
|
}
|
||||||
} catch (_) {
|
} catch (_) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_onError(e, stackTrace);
|
_onError(e, stackTrace);
|
||||||
canContinue = false;
|
canContinue = false;
|
||||||
|
@ -147,10 +148,14 @@ class Angel extends Routable {
|
||||||
}
|
}
|
||||||
|
|
||||||
_finalizeResponse(HttpRequest request, ResponseContext res) async {
|
_finalizeResponse(HttpRequest request, ResponseContext res) async {
|
||||||
|
try {
|
||||||
if (!res.willCloseItself) {
|
if (!res.willCloseItself) {
|
||||||
res.responseData.forEach((blob) => request.response.add(blob));
|
res.responseData.forEach((blob) => request.response.add(blob));
|
||||||
await request.response.close();
|
await request.response.close();
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Remember: This fails silently
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _randomString(int length) {
|
String _randomString(int length) {
|
||||||
|
@ -192,15 +197,24 @@ class Angel extends Routable {
|
||||||
if (stackTrace != null) stderr.write(stackTrace.toString());
|
if (stackTrace != null) stderr.write(stackTrace.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
Angel() : super() {}
|
Angel
|
||||||
|
()
|
||||||
|
:
|
||||||
|
super() {}
|
||||||
|
|
||||||
/// Creates an HTTPS server.
|
/// Creates an HTTPS server.
|
||||||
/// Provide paths to a certificate chain and server key (both .pem).
|
/// Provide paths to a certificate chain and server key (both .pem).
|
||||||
/// If no password is provided, a random one will be generated upon running
|
/// If no password is provided, a random one will be generated upon running
|
||||||
/// the server.
|
/// the server.
|
||||||
Angel.secure(String certificateChainPath, String serverKeyPath,
|
Angel.secure
|
||||||
{String password})
|
(String certificateChainPath, String
|
||||||
: super() {
|
serverKeyPath
|
||||||
|
,
|
||||||
|
{
|
||||||
|
String password
|
||||||
|
})
|
||||||
|
: super()
|
||||||
|
{
|
||||||
_serverGenerator = (InternetAddress address, int port) async {
|
_serverGenerator = (InternetAddress address, int port) async {
|
||||||
var certificateChain =
|
var certificateChain =
|
||||||
Platform.script.resolve('server_chain.pem').toFilePath();
|
Platform.script.resolve('server_chain.pem').toFilePath();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_framework
|
name: angel_framework
|
||||||
version: 0.0.0-dev.8
|
version: 0.0.0-dev.9
|
||||||
description: Core libraries for the Angel framework.
|
description: Core libraries for the Angel framework.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_framework
|
homepage: https://github.com/angel-dart/angel_framework
|
||||||
|
|
Loading…
Reference in a new issue