Index: pkg/shelf/lib/src/middleware.dart |
diff --git a/pkg/shelf/lib/src/middleware.dart b/pkg/shelf/lib/src/middleware.dart |
index 228761dea6862084c17f9872997140779a4692c6..b81b70d7ed85e384723920702690573dc66e0281 100644 |
--- a/pkg/shelf/lib/src/middleware.dart |
+++ b/pkg/shelf/lib/src/middleware.dart |
@@ -54,17 +54,21 @@ Middleware createMiddleware({requestHandler(Request request), |
if (responseHandler == null) responseHandler = (response) => response; |
+ var onError = null; |
+ if (errorHandler != null) { |
+ onError = (error, stackTrace) { |
+ if (error is HijackException) throw error; |
+ return errorHandler(error, stackTrace); |
+ }; |
+ } |
+ |
return (Handler innerHandler) { |
return (request) { |
return syncFuture(() => requestHandler(request)).then((response) { |
if (response != null) return response; |
return syncFuture(() => innerHandler(request)) |
- .then((response) => responseHandler(response), |
- onError: (error, stackTrace) { |
- if (error is HijackException) throw error; |
- return errorHandler(error, stackTrace); |
- }); |
+ .then((response) => responseHandler(response), onError: onError); |
}); |
}; |
}; |