Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/barback/base_server.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/barback/base_server.dart b/sdk/lib/_internal/pub/lib/src/barback/base_server.dart |
| index df9fef3410cfa0d5190dc25cd4b97184e49df9ed..5cd96683d0c228b85abab76223c5e27b925c72e9 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/barback/base_server.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/barback/base_server.dart |
| @@ -5,8 +5,10 @@ |
| library pub.barback.base_server; |
| import 'dart:async'; |
| +import 'dart:convert'; |
| import 'dart:io'; |
| +import 'package:barback/barback.dart'; |
| import 'package:stack_trace/stack_trace.dart'; |
| import '../log.dart' as log; |
| @@ -65,17 +67,31 @@ abstract class BaseServer<T> { |
| } |
| /// Responds to [request] with a 404 response and closes it. |
| - void notFound(HttpRequest request, message) { |
| - logRequest(request, "404 Not Found"); |
| + /// |
| + /// If [asset] is given, it is the ID of the asset that couldn't be found. |
| + void notFound(HttpRequest request, {String error, AssetId asset}) { |
| + logRequest(request, "Not Found"); |
| // Force a UTF-8 encoding so that error messages in non-English locales are |
| // sent correctly. |
| request.response.headers.contentType = |
| - ContentType.parse("text/plain; charset=utf-8"); |
| - |
| + ContentType.parse("text/html; charset=utf-8"); |
| request.response.statusCode = 404; |
| request.response.reasonPhrase = "Not Found"; |
| - request.response.write(message); |
| + |
| + // TODO(rnystrom): Apply some styling to make it visually clear that this |
| + // error is coming from pub serve itself. |
| + request.response.writeln("<h1>404 Not Found</h1>"); |
|
nweiz
2014/04/01 19:20:28
Now that this is HTML, it would be nice to provide
Bob Nystrom
2014/04/01 19:40:57
Done.
|
| + if (asset != null) { |
| + request.response.writeln("<p>Could not find asset " |
| + "<code>${HTML_ESCAPE.convert(asset.path)}</code> in package " |
| + "<code>${HTML_ESCAPE.convert(asset.package)}</code>.</p>"); |
| + } |
| + |
| + if (error != null) { |
| + request.response.writeln("<p>Error: $error</p>"); |
|
nweiz
2014/04/01 19:20:28
Don't forget to escape this too!
Bob Nystrom
2014/04/01 19:40:57
Oops! Done.
|
| + } |
| + |
| request.response.close(); |
| } |