Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Unified Diff: lib/src/client.dart

Issue 1341933002: Improve stack traces for error responses. (Closed) Base URL: git@github.com:dart-lang/json_rpc_2.git@master
Patch Set: changelog Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/client.dart
diff --git a/lib/src/client.dart b/lib/src/client.dart
index f63fde6cb8ca4d60d2299dcdb0bb0624d191f048..ee2db1e9ff38540636d8fe8a00e283cf35b3b3f2 100644
--- a/lib/src/client.dart
+++ b/lib/src/client.dart
@@ -28,9 +28,8 @@ class Client {
/// Each element is a JSON-serializable object.
List _batch;
- /// The map of request ids for pending requests to [Completer]s that will be
- /// completed with those requests' responses.
- final _pendingRequests = new Map<int, Completer>();
+ /// The map of request ids to pending requests.
+ final _pendingRequests = new Map<int, _Request>();
/// Returns a [Future] that completes when the connection is closed.
///
@@ -94,7 +93,7 @@ class Client {
_send(method, parameters, id);
var completer = new Completer.sync();
- _pendingRequests[id] = completer;
+ _pendingRequests[id] = new _Request(completer, new Chain.current());
return completer.future;
}
@@ -171,15 +170,15 @@ class Client {
/// resolved.
void _handleSingleResponse(response) {
if (!_isResponseValid(response)) return;
- var completer = _pendingRequests.remove(response["id"]);
+ var request = _pendingRequests.remove(response["id"]);
if (response.containsKey("result")) {
- completer.complete(response["result"]);
+ request.completer.complete(response["result"]);
} else {
- completer.completeError(new RpcException(
+ request.completer.completeError(new RpcException(
response["error"]["code"],
response["error"]["message"],
data: response["error"]["data"]),
- new Chain.current());
+ request.chain);
}
}
@@ -198,3 +197,14 @@ class Client {
return true;
}
}
+
+/// A pending request to the server.
+class _Request {
+ /// The completer to use to complete the response future.
+ final Completer completer;
+
+ /// The stack chain from where the request was made.
+ final Chain chain;
+
+ _Request(this.completer, this.chain);
+}
« no previous file with comments | « CHANGELOG.md ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698