Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit 28e06fe

Browse files
committed
Fix connection timeout when throwing/returning an ErrorResponse within a Future; Fix crash when reading text files in multipart requests
1 parent 4c46c56 commit 28e06fe

File tree

7 files changed

+62
-13
lines changed

7 files changed

+62
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
##v0.5.21
2+
3+
* Fix connection timeout when throwing/returning an ErrorResponse within a Future ([#83](https://github.com/luizmineo/redstone.dart/issues/83))
4+
* Fix crash when reading text files in multipart requests ([#77](https://github.com/luizmineo/redstone.dart/issues/77))
5+
16
##v0.5.20
27

38
* Update `route_hierarchical` version constraint.
49

510
##v0.5.19
6-
* Fix: Error when setting `Intereptor.parseRequestBody = true` (Thanks to [platelk](https://github.com/platelk). See PR [#46](https://github.com/luizmineo/redstone.dart/pull/46)).
11+
* Fix: Error when setting `Interceptor.parseRequestBody = true` (Thanks to [platelk](https://github.com/platelk). See PR [#46](https://github.com/luizmineo/redstone.dart/pull/46)).
712

813
## v0.5.18
914
* Updated to Grinder v0.6.1 (see [documentation](https://github.com/luizmineo/redstone.dart/wiki/Deploy))

lib/src/http_body_parser.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ part of redstone_server;
77
class HttpBodyFileUpload {
88
final ContentType contentType;
99
final String filename;
10-
final List<int> content;
10+
final dynamic content;
1111

1212
HttpBodyFileUpload(this.contentType, this.filename, this.content);
1313

lib/src/server_impl.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,17 +462,21 @@ Future _writeResponse(respValue, String responseType, {int statusCode: 200,
462462
} else if (respValue is Future) {
463463

464464
respValue.then((fValue) {
465+
if (fValue is ErrorResponse) {
466+
throw fValue;
467+
}
465468
return _writeResponse(fValue, responseType,
466469
statusCode: statusCode,
467470
processors: processors,
468471
abortIfChainInterrupted: abortIfChainInterrupted);
469472
}).then((_) {
470473
completer.complete();
471-
}).catchError((e) {
472-
return _writeResponse(e, responseType,
474+
}).catchError((e, s) {
475+
var f = _writeResponse(e, responseType,
473476
statusCode: statusCode,
474477
processors: processors,
475478
abortIfChainInterrupted: abortIfChainInterrupted);
479+
f.then((_) => completer.completeError(e, s));
476480
}, test: (e) => e is ErrorResponse)
477481
.catchError((e, s) {
478482
completer.completeError(e, s);
@@ -629,7 +633,7 @@ void _writeErrorPage(int statusCode, String resource, [Object error, StackTrace
629633
<pre>${error}${formattedStack != null ? "\n\n" + formattedStack : ""}</pre>
630634
</div>
631635
</div>
632-
<div class="footer">Redstone Server - 2014 - Luiz Mineo</div>
636+
<div class="footer">Redstone Server - 2015 - Luiz Mineo</div>
633637
</body>
634638
</html>''';
635639

lib/src/setup_impl.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ void _scanHandlers([List<Symbol> libraries]) {
374374
currentLevel = 0;
375375
levelHist = [];
376376
groups.forEach((g) {
377-
List<int> chainIdxByLevel;
378377
if (g.lib.level > currentLevel) {
379378
currentLevel = g.lib.level;
380379
levelHist.add(g.lib.conf.chainIdx);
@@ -813,8 +812,14 @@ void _configureTarget(_ServerMetadataImpl serverMetadata,
813812
logLevel: Level.FINER,
814813
printErrorPage: false);
815814
}
816-
});
817-
815+
}).catchError((e, s) {
816+
chain.error = e.error;
817+
return _handleError("ErrorResponse returned by $handlerName",
818+
e.error, req: request,
819+
statusCode: e.statusCode,
820+
logLevel: Level.FINER,
821+
printErrorPage: false);
822+
}, test: (e) => e is ErrorResponse);
818823
});
819824

820825
};

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: redstone
2-
version: 0.5.20
2+
version: 0.5.21
33
author: Luiz Mineo <[email protected]>
44
description: A metadata driven microframework for Dart
55
homepage: http://redstonedart.org

test/server_tests.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,31 @@ main() {
388388
});
389389

390390
test("Error response", () {
391-
var req = new MockRequest("/error_response");
391+
var req = new MockRequest("/error_response/sync");
392+
return app.dispatch(req).then((resp) {
393+
expect(resp.statusCode, equals(400));
394+
expect(resp.mockContent, equals("handling: error_response"));
395+
});
396+
});
397+
398+
test("async error response", () {
399+
var req = new MockRequest("/error_response/async");
400+
return app.dispatch(req).then((resp) {
401+
expect(resp.statusCode, equals(400));
402+
expect(resp.mockContent, equals("handling: error_response"));
403+
});
404+
});
405+
406+
test("throw error response", () {
407+
var req = new MockRequest("/error_response/throw/sync");
408+
return app.dispatch(req).then((resp) {
409+
expect(resp.statusCode, equals(400));
410+
expect(resp.mockContent, equals("handling: error_response"));
411+
});
412+
});
413+
414+
test("async throw error response", () {
415+
var req = new MockRequest("/error_response/throw/async");
392416
return app.dispatch(req).then((resp) {
393417
expect(resp.statusCode, equals(400));
394418
expect(resp.mockContent, equals("handling: error_response"));

test/services/errors.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,21 @@ subHandler() => throw "server_error";
6161
subErrorHandler() => new shelf.Response.internalServerError(
6262
body: "${app.chain.error} sub_error_handler");
6363

64-
@app.Route("/error_response")
65-
errorResponse() => throw new app.ErrorResponse(400, "error_response");
64+
@app.Route("/error_response/sync")
65+
errorResponse() => new app.ErrorResponse(400, "error_response");
6666

67-
@app.ErrorHandler(400, urlPattern: "/error_response")
67+
@app.Route("/error_response/async")
68+
asyncErrorResponse() => new Future(() =>
69+
new app.ErrorResponse(400, "error_response"));
70+
71+
@app.Route("/error_response/throw/sync")
72+
throwErrorResponse() => throw new app.ErrorResponse(400, "error_response");
73+
74+
@app.Route("/error_response/throw/async")
75+
asyncThrowErrorResponse() => new Future(() =>
76+
throw new app.ErrorResponse(400, "error_response"));
77+
78+
@app.ErrorHandler(400, urlPattern: "/error_response/.*")
6879
handleErrorResponse() {
6980
return app.response.readAsString().then((resp) {
7081
return new shelf.Response(app.response.statusCode,

0 commit comments

Comments
 (0)