ExceptionFilter<T extends Object> class abstract

Exception filter middleware for Spry.

Create class-based exception filter

class MyExceptionFilter extends ExceptionFilter<MyException> {
  @override
  void handler(Context context, MyException exception, StackTrace stackTrace) {
  context.response.statusCode = 500;
  context.response.send(exception.toString());
 }
}

Create function-based exception filter

final ExceptionFilter<MyException> myExceptionFilter = ExceptionFilter.fromHandler((context, exception, stackTrace) {
 context.response.statusCode = 500;
 context.response.send(exception.toString());
});

Note: If you want to pass the final exception error to the interceptor, you should put the filter after the interceptor, and then throw the error in ExceptionFilterHandler.

Constructors

ExceptionFilter.new()
const
ExceptionFilter.fromHandler(FutureOr<void> handler(Context context, T exception, StackTrace stackTrace))
Creates a new ExceptionFilter from a handler function.
factory

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

call(Context context, Next next) FutureOr<void>
The exception filter middleware-style function.
handler(Context context, T exception, StackTrace stack) FutureOr<void>
The exception filter handler function.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited