diff --git a/.gitignore b/.gitignore index d1fc3f5..0224905 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ .packages .project .pub/ +.scripts-bin/ build/ **/packages/ @@ -73,4 +74,11 @@ crashlytics.properties crashlytics-build.properties fabric.properties +### VSCode template +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + logs/**/*.txt \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..05bc677 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Start Server", + "type": "dart-cli", + "request": "launch", + "cwd": "${workspaceRoot}", + "debugSettings": "${command.debugSettings}", + "program": "${workspaceRoot}/bin/server.dart", + "args": [], + "preLaunchTask": "pub:serve" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..7ce762d --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,25 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "0.1.0", + "command": "pub", + "isShellCommand": true, + "echoCommand": true, + "showOutput": "always", + "tasks": [ + { + "taskName": "pub:build", + "suppressTaskName": true, + "args": [ + "build" + ] + }, + { + "taskName": "pub:serve", + "suppressTaskName": true, + "args": [ + "serve" + ] + } + ] +} \ No newline at end of file diff --git a/analysis_options.yaml b/analysis_options.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/lib/src/routes/routes.dart b/lib/src/routes/routes.dart index 0f55859..8c1ff75 100644 --- a/lib/src/routes/routes.dart +++ b/lib/src/routes/routes.dart @@ -2,6 +2,7 @@ library angel.routes; import 'package:angel_cors/angel_cors.dart'; +import 'package:angel_errors/angel_errors.dart'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_proxy/angel_proxy.dart'; import 'package:angel_static/angel_static.dart'; @@ -19,14 +20,32 @@ configureRoutes(Angel app) async { } configureAfter(Angel app) async { - // 404 handler - app.after.add((req, ResponseContext res) async { - throw new AngelHttpException.NotFound(); + // Set our application up to handle different errors. + var errors = new ErrorHandler(handlers: { + 404: (req, res) async => + res.render('error', {'message': 'No file exists at ${req.path}.'}), + 500: (req, res) async => res.render('error', {'message': req.error.message}) }); - // Default error handler - app.onError( - (e, req, res) async => res.render('error', {'message': e.message})); + errors.fatalErrorHandler = (AngelFatalError e) async { + e.request.response + ..statusCode = 500 + ..writeln('500 Internal Server Error: ${e.error}') + ..writeln(e.stack); + await e.request.response.close(); + }; + + // Throw a 404 if no route matched the request + app.after.add(errors.throwError()); + + // Handle errors when they occur, based on outgoing status code. + // By default, requests will go through the 500 handler, unless + // they have an outgoing 200, or their status code has a handler + // registered. + app.after.add(errors.middleware()); + + // Pass AngelHttpExceptions through handler as well + await app.configure(errors); } configureServer(Angel app) async { diff --git a/pubspec.yaml b/pubspec.yaml index 2620b82..f2b8dbd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,26 +1,27 @@ -name: angel -description: An easily-extensible web server framework in Dart. -version: 1.0.0-dev -author: Tobe O -homepage: https://github.com/angel-dart/angel -publish_to: none -dependencies: - angel_auth: ^1.0.0-dev - angel_configuration: ^1.0.0-dev - angel_cors: ^1.0.0-dev - angel_diagnostics: ^1.0.0-dev - angel_errors: ^1.0.0-dev - angel_framework: ^1.0.0-dev - angel_mongo: ^1.0.0-dev - angel_mustache: ^1.0.0-dev - angel_proxy: ^1.0.0-dev - angel_static: ^1.1.0-dev - angel_test: ^1.0.0-dev - mailer: ^1.1.0+4 - validate: ^1.5.2 -dev_dependencies: - http: ^0.11.3 - grinder: ^0.8.0+2 - test: ^0.12.13 -transformers: -- angel_configuration +author: "Tobe O" +description: "An easily-extensible web server framework in Dart." +homepage: "https://github.com/angel-dart/angel" +name: "angel" +publish_to: "none" +version: "1.0.0-dev" +dependencies: + angel_auth: "^1.0.0-dev" + angel_compress: "^1.0.0" + angel_configuration: "^1.0.0-dev" + angel_cors: "^1.0.0-dev" + angel_diagnostics: "^1.0.0-dev" + angel_errors: "^1.0.0-dev" + angel_framework: "^1.0.0-dev" + angel_mongo: "^1.0.0-dev" + angel_mustache: "^1.0.0-dev" + angel_proxy: "^1.0.0-dev" + angel_static: "^1.1.0-dev" + angel_test: "^1.0.0-dev" + mailer: "^1.1.0+4" + validate: "^1.5.2" +dev_dependencies: + grinder: "^0.8.0+2" + http: "^0.11.3" + test: "^0.12.13" +transformers: + - "angel_configuration" diff --git a/views/error.mustache b/views/error.mustache index 1b0226b..201c32f 100644 --- a/views/error.mustache +++ b/views/error.mustache @@ -1,7 +1,7 @@
-