OLD | NEW |
(Empty) | |
| 1 >>> |
| 2 return environment.barback.getAssetById(id).then((result) { |
| 3 return result; |
| 4 }).then((asset) => _serveAsset(request, asset)).catchError( |
| 5 (error, |
| 6 trace) { |
| 7 if (error is! AssetNotFoundException) throw error; |
| 8 return environment.barback |
| 9 .getAssetById(id.addExtension("/index.html")) |
| 10 .then((asset) { |
| 11 if (request.url.path.endsWith('/')) return _serveAsset(request, asset); |
| 12 |
| 13 // We only want to serve index.html if the URL explicitly ends in a |
| 14 // slash. For other URLs, we redirect to one with the slash added to |
| 15 // implicitly support that too. This follows Apache's behavior. |
| 16 logRequest(request, "302 Redirect to ${request.url}/"); |
| 17 return new shelf.Response.found('${request.url}/'); |
| 18 }).catchError((newError, newTrace) { |
| 19 // If we find neither the original file or the index, we should report |
| 20 // the error about the original to the user. |
| 21 throw newError is AssetNotFoundException ? error : newError; |
| 22 }); |
| 23 }).catchError( |
| 24 (error, |
| 25 trace) { |
| 26 if (error is! AssetNotFoundException) { |
| 27 trace = new Chain.forTrace(trace); |
| 28 logRequest(request, "$error\n$trace"); |
| 29 |
| 30 addError(error, trace); |
| 31 close(); |
| 32 return new shelf.Response.internalServerError(); |
| 33 } |
| 34 |
| 35 addResult(new BarbackServerResult._failure(request.url, id, error)); |
| 36 return notFound(request, asset: id); |
| 37 }); |
| 38 <<< |
| 39 return environment.barback.getAssetById(id).then((result) { |
| 40 return result; |
| 41 }).then((asset) => _serveAsset(request, asset)).catchError((error, trace) { |
| 42 if (error is! AssetNotFoundException) throw error; |
| 43 return environment.barback |
| 44 .getAssetById(id.addExtension("/index.html")) |
| 45 .then((asset) { |
| 46 if (request.url.path.endsWith('/')) return _serveAsset(request, asset); |
| 47 |
| 48 // We only want to serve index.html if the URL explicitly ends in a |
| 49 // slash. For other URLs, we redirect to one with the slash added to |
| 50 // implicitly support that too. This follows Apache's behavior. |
| 51 logRequest(request, "302 Redirect to ${request.url}/"); |
| 52 return new shelf.Response.found('${request.url}/'); |
| 53 }).catchError((newError, newTrace) { |
| 54 // If we find neither the original file or the index, we should report |
| 55 // the error about the original to the user. |
| 56 throw newError is AssetNotFoundException ? error : newError; |
| 57 }); |
| 58 }).catchError((error, trace) { |
| 59 if (error is! AssetNotFoundException) { |
| 60 trace = new Chain.forTrace(trace); |
| 61 logRequest(request, "$error\n$trace"); |
| 62 |
| 63 addError(error, trace); |
| 64 close(); |
| 65 return new shelf.Response.internalServerError(); |
| 66 } |
| 67 |
| 68 addResult(new BarbackServerResult._failure(request.url, id, error)); |
| 69 return notFound(request, asset: id); |
| 70 }); |
OLD | NEW |