ExceptionHandler class
The one place that turns a thrown error into a response.
Extend it and set it in AppConfig(exceptionHandler: ...).
class AppExceptionHandler extends ExceptionHandler {
@override
void report(Object error, StackTrace stackTrace) {
sentry.captureException(error, stackTrace: stackTrace);
}
@override
dynamic render(Object error, HttpRequest req) {
if (error is PaymentRequiredException) {
return response({'message': 'Please pay'}).statusCode(402);
}
return super.render(error, req);
}
}
Constructors
- ExceptionHandler()
-
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
render(
Object error, HttpRequest req) → dynamic -
What to send for
error. Return anything a controller can return: aDoxResponse, a map, a string. Returnerroritself (the default) for the default answer: -
report(
Object error, StackTrace stackTrace) → void -
Log the error. Dox calls it for every error that is not an
IHttpException(those are normal answers like 404 or 422), and for errors outside a request, like a future that nobody awaited. The default prints the error and the stack with the logger. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited