Closed petermetz closed 10 years ago
Hi @petermetz,
Unfortunately, bloodless doesn't support defining error handlers inside groups yet. Actually, you can have only one error handler per status code in your application, but I plan to remove this restriction in future releases.
Hi @luizmineo,
Thanks for quick response and especially the extra info, I wasn't aware of that at all! I modified my test case by removing the group and the error handler is still not getting called. Do you know what I might be missing?
import 'dart:io';
import 'package:bloodless/server.dart' as app;
main() {
app.setupConsoleLog();
app.start();
}
@app.ErrorHandler(HttpStatus.INTERNAL_SERVER_ERROR)
handleInternalServerError() {
print('Internal server error occured!');
}
@app.Route('/b')
String defaultHandler() {
print('Executing the default handler.');
app.abort(HttpStatus.INTERNAL_SERVER_ERROR);
return 'This is the default response.';
}
Well, this is indeed a bug in bloodless :(
The error handler is being called, but the response returned by the router is overwriting the response generated by the abort() method.
As a workaround, you can just throw an exception, instead of calling abort(). I will provide a fix for this in a future release.
I will do just like that, thank you very much again for the quick help.
I'm looking forward to those upcoming releases, the framework/library looks awesome so far, reminds me of JAX-RS.
Kind regards, Peter
Hiya,
I was trying to set up an error handler and couldn't get it working. I'm not sure if it's my code or the library. Could you please have a look at my test case for which I'd expect the error handler to be called?
I'm on Dart 1.3 stable and the exact link I was testing is this: http://localhost:8080/a/b