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

Side by Side Diff: pkg/scheduled_test/lib/scheduled_server.dart

Issue 23591061: Make package:scheduled_test throw ScheduledServerErrors, not strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix formatting and stray code. Created 7 years, 3 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 scheduled_test.scheduled_server; 5 library scheduled_test.scheduled_server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:io'; 9 import 'dart:io';
10 10
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 }, "'$description' waiting for $method $path"); 84 }, "'$description' waiting for $method $path");
85 } 85 }
86 86
87 /// The handler for incoming [HttpRequest]s to this server. This dispatches 87 /// The handler for incoming [HttpRequest]s to this server. This dispatches
88 /// the request to the first handler in the queue. It's that handler's 88 /// the request to the first handler in the queue. It's that handler's
89 /// responsibility to check that the method/path are correct and that it's 89 /// responsibility to check that the method/path are correct and that it's
90 /// being run at the correct time. 90 /// being run at the correct time.
91 void _handleRequest(HttpRequest request) { 91 void _handleRequest(HttpRequest request) {
92 wrapFuture(new Future.sync(() { 92 wrapFuture(new Future.sync(() {
93 if (_handlers.isEmpty) { 93 if (_handlers.isEmpty) {
94 throw "'$description' received ${request.method} ${request.uri.path} " 94 throw new ScheduledServerError(
95 "when no more requests were expected."; 95 "'$description' received ${request.method} ${request.uri.path} "
96 "when no more requests were expected.");
96 } 97 }
97 return _handlers.removeFirst().fn(request); 98 return _handlers.removeFirst().fn(request);
98 }).catchError((e) { 99 }).catchError((e) {
99 // Close the server so that we don't leave a dangling request. 100 // Close the server so that we don't leave a dangling request.
100 _server.then((s) => s.close()); 101 _server.then((s) => s.close());
101 throw e; 102 throw e;
102 }), 'receiving ${request.method} ${request.uri}'); 103 }), 'receiving ${request.method} ${request.uri}');
103 } 104 }
104 } 105 }
106
107
108 class ScheduledServerError extends Error {
nweiz 2013/09/19 19:56:14 I'm not a fan of using a custom error class here.
Bill Hesse 2013/09/20 13:30:20 Done.
109 final String message;
110
111 ScheduledServerError(String this.message);
112
113 String toString() => 'ScheduledServerError: $message';
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698