Controllers should be able to handle errors themselves
This commit is contained in:
parent
1a7d831a36
commit
76d26ea9c5
4 changed files with 90 additions and 84 deletions
|
@ -52,7 +52,6 @@ class Controller {
|
||||||
ResponseContext res) async {
|
ResponseContext res) async {
|
||||||
List args = [];
|
List args = [];
|
||||||
|
|
||||||
try {
|
|
||||||
// Load parameters, and execute
|
// Load parameters, and execute
|
||||||
for (int i = 0; i < methodMirror.parameters.length; i++) {
|
for (int i = 0; i < methodMirror.parameters.length; i++) {
|
||||||
ParameterMirror parameter = methodMirror.parameters[i];
|
ParameterMirror parameter = methodMirror.parameters[i];
|
||||||
|
@ -76,9 +75,6 @@ class Controller {
|
||||||
return await instanceMirror
|
return await instanceMirror
|
||||||
.invoke(key, args)
|
.invoke(key, args)
|
||||||
.reflectee;
|
.reflectee;
|
||||||
} catch (e) {
|
|
||||||
throw new AngelHttpException(e);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
Route route = new Route(
|
Route route = new Route(
|
||||||
exposeMirror.reflectee.method,
|
exposeMirror.reflectee.method,
|
||||||
|
|
|
@ -83,7 +83,7 @@ class ResponseContext extends Extensible {
|
||||||
<body>
|
<body>
|
||||||
<h1>Currently redirecting you...</h1>
|
<h1>Currently redirecting you...</h1>
|
||||||
<br />
|
<br />
|
||||||
Click <a href="$url"></a> if you are not automatically redirected...
|
Click <a href="$url">here</a> if you are not automatically redirected...
|
||||||
<script>
|
<script>
|
||||||
window.location = "$url";
|
window.location = "$url";
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -12,6 +12,12 @@ typedef Future AngelConfigurer(Angel app);
|
||||||
|
|
||||||
/// A powerful real-time/REST/MVC server class.
|
/// A powerful real-time/REST/MVC server class.
|
||||||
class Angel extends Routable {
|
class Angel extends Routable {
|
||||||
|
var _beforeProcessed = new StreamController<HttpRequest>();
|
||||||
|
var _afterProcessed = new StreamController<HttpRequest>();
|
||||||
|
|
||||||
|
Stream<HttpRequest> get beforeProcessed => _beforeProcessed.stream;
|
||||||
|
Stream<HttpRequest> get afterProcessed => _afterProcessed.stream;
|
||||||
|
|
||||||
ServerGenerator _serverGenerator =
|
ServerGenerator _serverGenerator =
|
||||||
(address, port) async => await HttpServer.bind(address, port);
|
(address, port) async => await HttpServer.bind(address, port);
|
||||||
|
|
||||||
|
@ -50,7 +56,13 @@ class Angel extends Routable {
|
||||||
await _serverGenerator(address ?? InternetAddress.LOOPBACK_IP_V4, port);
|
await _serverGenerator(address ?? InternetAddress.LOOPBACK_IP_V4, port);
|
||||||
this.httpServer = server;
|
this.httpServer = server;
|
||||||
|
|
||||||
server.listen((HttpRequest request) async {
|
server.listen(handleRequest);
|
||||||
|
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future handleRequest(HttpRequest request) async {
|
||||||
|
_beforeProcessed.add(request);
|
||||||
String req_url =
|
String req_url =
|
||||||
request.uri.toString().replaceAll("?" + request.uri.query, "").replaceAll(new RegExp(r'\/+$'), '');
|
request.uri.toString().replaceAll("?" + request.uri.query, "").replaceAll(new RegExp(r'\/+$'), '');
|
||||||
if (req_url.isEmpty) req_url = '/';
|
if (req_url.isEmpty) req_url = '/';
|
||||||
|
@ -108,9 +120,6 @@ class Angel extends Routable {
|
||||||
await execHandler(handler, req);
|
await execHandler(handler, req);
|
||||||
}
|
}
|
||||||
_finalizeResponse(request, res);
|
_finalizeResponse(request, res);
|
||||||
});
|
|
||||||
|
|
||||||
return server;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> _applyHandler(
|
Future<bool> _applyHandler(
|
||||||
|
@ -162,6 +171,7 @@ class Angel extends Routable {
|
||||||
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();
|
||||||
|
_afterProcessed.add(request);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Remember: This fails silently
|
// Remember: This fails silently
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_framework
|
name: angel_framework
|
||||||
version: 1.0.0-dev.8
|
version: 1.0.0-dev.13
|
||||||
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