addInterceptor method Null safety
- DartnessInterceptor interceptor
override
Returns a new DartnessPipeline with middleware
added to the existing set of
DartnessInterceptor.
Implementation
@override
DartnessPipeline addInterceptor(final DartnessInterceptor interceptor) {
final pipeline = _pipeline.addMiddleware((final Handler innerHandler) {
return (final Request request) {
interceptor.onRequest(request);
return Future.sync(() => innerHandler(request))
.then((final Response response) {
interceptor.onResponse(response);
return response;
}).catchError((Object error, StackTrace stackTrace) {
interceptor.onError(error, stackTrace);
});
};
});
return DefaultDartnessPipeline(pipeline: pipeline);
}