Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/command/serve.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/command/serve.dart b/sdk/lib/_internal/pub/lib/src/command/serve.dart |
| index ce8db31dd2ea7328041b23ae7a0ac9ad0e4ab491..544f94083e748ab6942419f1e19b46316087c83e 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/command/serve.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/command/serve.dart |
| @@ -78,14 +78,14 @@ class ServeCommand extends PubCommand { |
| // are added or modified. |
| HttpServer.bind("localhost", port).then((server) { |
| - log.message("Serving ${entrypoint.root.name} " |
| - "on http://localhost:${server.port}"); |
| - |
| // Add all of the visible files. |
| for (var package in provider.packages) { |
| barback.updateSources(provider.listAssets(package)); |
| } |
| + log.message("Serving ${entrypoint.root.name} " |
| + "on http://localhost:${server.port}"); |
| + |
| server.listen((request) { |
| var id = getIdFromUri(request.uri); |
| if (id == null) { |
| @@ -93,14 +93,30 @@ class ServeCommand extends PubCommand { |
| } |
| barback.getAssetById(id).then((asset) { |
| - log.message( |
| - "$_green${request.method}$_none ${request.uri} -> $asset"); |
| - // TODO(rnystrom): Set content-type based on asset type. |
| - return request.response.addStream(asset.read()).then((_) { |
| + return validateStream(asset.read()).then((stream) { |
| + log.message( |
| + "$_green${request.method}$_none ${request.uri} -> $asset"); |
| + // TODO(rnystrom): Set content-type based on asset type. |
| + return request.response.addStream(stream).then((_) { |
| + request.response.close(); |
| + }); |
| + }).catchError((error) { |
| + log.error("$_red${request.method}$_none ${request.uri} -> $error"); |
|
nweiz
2013/08/12 20:26:31
long line
Bob Nystrom
2013/08/12 21:45:00
Done.
|
| + |
| + // If we couldn't read the asset, handle the error gracefully. |
| + if (error is FileException) { |
| + // Assume this means the asset was a file-backed source asset |
| + // and we couldn't read it, so treat it like a missing asset. |
| + notFound(request, error); |
| + return; |
| + } |
| + |
| + // Otherwise, it's some internal error. |
| + request.response.statusCode = 500; |
| + request.response.reasonPhrase = "Internal Error"; |
| + request.response.write(error); |
| request.response.close(); |
| }); |
| - // TODO(rnystrom): Serve up a 500 if we get an error reading the |
| - // asset. |
| }).catchError((error) { |
| log.error("$_red${request.method}$_none ${request.uri} -> $error"); |
| if (error is! AssetNotFoundException) { |