Fail tests on errors thrown by test PackageServer (#3784)

diff --git a/test/oauth2/with_no_credentials_authenticates_and_saves_credentials_test.dart b/test/oauth2/with_no_credentials_authenticates_and_saves_credentials_test.dart
index abe365f..ba5bc01 100644
--- a/test/oauth2/with_no_credentials_authenticates_and_saves_credentials_test.dart
+++ b/test/oauth2/with_no_credentials_authenticates_and_saves_credentials_test.dart
@@ -22,7 +22,7 @@
     globalServer.expect('GET', '/api/packages/versions/new', (request) {
       expect(
         request.headers,
-        containsPair('authorization', 'Bearer access token'),
+        containsPair('authorization', 'Bearer access-token'),
       );
 
       return shelf.Response(200);
diff --git a/test/package_server.dart b/test/package_server.dart
index 9990a5f..a2dd4f5 100644
--- a/test/package_server.dart
+++ b/test/package_server.dart
@@ -45,19 +45,27 @@
   bool serveChecksums = true;
 
   PackageServer._(this._inner) {
+    final outerZone = Zone.current;
     _inner.mount((request) {
-      final path = request.url.path;
-      requestedPaths.add(path);
-
-      final pathWithInitialSlash = '/$path';
-      for (final entry in _handlers.reversed) {
-        final match = entry.pattern.matchAsPrefix(pathWithInitialSlash);
-        if (match != null && match.end == pathWithInitialSlash.length) {
-          final a = entry.handler(request);
-          return a;
+      try {
+        final path = request.url.path;
+        requestedPaths.add(path);
+        final pathWithInitialSlash = '/$path';
+        for (final entry in _handlers.reversed) {
+          final match = entry.pattern.matchAsPrefix(pathWithInitialSlash);
+          if (match != null && match.end == pathWithInitialSlash.length) {
+            final a = entry.handler(request);
+            return a;
+          }
         }
+        return shelf.Response.notFound('Could not find ${request.url}');
+      } catch (e, st) {
+        // Because shelf swallows all errors we catch here and redirect to the
+        // zone error handler.
+        outerZone.handleUncaughtError(e, st);
+        _inner.close();
+        rethrow;
       }
-      return shelf.Response.notFound('Could not find ${request.url}');
     });
   }