Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: pkg/shelf/lib/src/middleware.dart

Issue 657543004: pkg/shelf: only catch errors in createMiddleware if an errorHandler is provided (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address CL comments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/shelf/CHANGELOG.md ('k') | pkg/shelf/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library shelf.middleware; 5 library shelf.middleware;
6 6
7 import 'request.dart'; 7 import 'request.dart';
8 import 'response.dart'; 8 import 'response.dart';
9 import 'handler.dart'; 9 import 'handler.dart';
10 import 'hijack_exception.dart'; 10 import 'hijack_exception.dart';
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 /// does not receive errors thrown by [requestHandler] or [responseHandler], nor 47 /// does not receive errors thrown by [requestHandler] or [responseHandler], nor
48 /// does it receive [HijackException]s. It can either return a new response or 48 /// does it receive [HijackException]s. It can either return a new response or
49 /// throw an error. 49 /// throw an error.
50 Middleware createMiddleware({requestHandler(Request request), 50 Middleware createMiddleware({requestHandler(Request request),
51 responseHandler(Response response), 51 responseHandler(Response response),
52 errorHandler(error, StackTrace stackTrace)}) { 52 errorHandler(error, StackTrace stackTrace)}) {
53 if (requestHandler == null) requestHandler = (request) => null; 53 if (requestHandler == null) requestHandler = (request) => null;
54 54
55 if (responseHandler == null) responseHandler = (response) => response; 55 if (responseHandler == null) responseHandler = (response) => response;
56 56
57 var onError = null;
58 if (errorHandler != null) {
59 onError = (error, stackTrace) {
60 if (error is HijackException) throw error;
61 return errorHandler(error, stackTrace);
62 };
63 }
64
57 return (Handler innerHandler) { 65 return (Handler innerHandler) {
58 return (request) { 66 return (request) {
59 return syncFuture(() => requestHandler(request)).then((response) { 67 return syncFuture(() => requestHandler(request)).then((response) {
60 if (response != null) return response; 68 if (response != null) return response;
61 69
62 return syncFuture(() => innerHandler(request)) 70 return syncFuture(() => innerHandler(request))
63 .then((response) => responseHandler(response), 71 .then((response) => responseHandler(response), onError: onError);
64 onError: (error, stackTrace) {
65 if (error is HijackException) throw error;
66 return errorHandler(error, stackTrace);
67 });
68 }); 72 });
69 }; 73 };
70 }; 74 };
71 } 75 }
OLDNEW
« no previous file with comments | « pkg/shelf/CHANGELOG.md ('k') | pkg/shelf/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698