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

Side by Side Diff: pkg/oauth2/lib/src/handle_access_token_response.dart

Issue 11308110: Add TODOs about narrowing JSON catch clauses to the OAuth2 package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/oauth2/lib/src/credentials.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library handle_access_token_response; 5 library handle_access_token_response;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:json'; 8 import 'dart:json';
9 import 'dart:uri'; 9 import 'dart:uri';
10 10
(...skipping 24 matching lines...) Expand all
35 if (contentType != null) { 35 if (contentType != null) {
36 contentType = new ContentType.fromString(contentType); 36 contentType = new ContentType.fromString(contentType);
37 } 37 }
38 validate(contentType != null && contentType.value == "application/json", 38 validate(contentType != null && contentType.value == "application/json",
39 'content-type was "$contentType", expected "application/json"'); 39 'content-type was "$contentType", expected "application/json"');
40 40
41 var parameters; 41 var parameters;
42 try { 42 try {
43 parameters = JSON.parse(response.body); 43 parameters = JSON.parse(response.body);
44 } catch (e) { 44 } catch (e) {
45 // TODO(nweiz): narrow this catch clause once issue 6775 is fixed.
45 validate(false, 'invalid JSON'); 46 validate(false, 'invalid JSON');
46 } 47 }
47 48
48 for (var requiredParameter in ['access_token', 'token_type']) { 49 for (var requiredParameter in ['access_token', 'token_type']) {
49 validate(parameters.containsKey(requiredParameter), 50 validate(parameters.containsKey(requiredParameter),
50 'did not contain required parameter "$requiredParameter"'); 51 'did not contain required parameter "$requiredParameter"');
51 validate(parameters[requiredParameter] is String, 52 validate(parameters[requiredParameter] is String,
52 'required parameter "$requiredParameter" was not a string, was ' 53 'required parameter "$requiredParameter" was not a string, was '
53 '"${parameters[requiredParameter]}"'); 54 '"${parameters[requiredParameter]}"');
54 } 55 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (contentType != null) { 105 if (contentType != null) {
105 contentType = new ContentType.fromString(contentType); 106 contentType = new ContentType.fromString(contentType);
106 } 107 }
107 validate(contentType != null && contentType.value == "application/json", 108 validate(contentType != null && contentType.value == "application/json",
108 'content-type was "$contentType", expected "application/json"'); 109 'content-type was "$contentType", expected "application/json"');
109 110
110 var parameters; 111 var parameters;
111 try { 112 try {
112 parameters = JSON.parse(response.body); 113 parameters = JSON.parse(response.body);
113 } catch (e) { 114 } catch (e) {
115 // TODO(nweiz): narrow this catch clause once issue 6775 is fixed.
114 validate(false, 'invalid JSON'); 116 validate(false, 'invalid JSON');
115 } 117 }
116 118
117 validate(parameters.containsKey('error'), 119 validate(parameters.containsKey('error'),
118 'did not contain required parameter "error"'); 120 'did not contain required parameter "error"');
119 validate(parameters["error"] is String, 121 validate(parameters["error"] is String,
120 'required parameter "error" was not a string, was ' 122 'required parameter "error" was not a string, was '
121 '"${parameters["error"]}"'); 123 '"${parameters["error"]}"');
122 124
123 for (var name in ['error_description', 'error_uri']) { 125 for (var name in ['error_description', 'error_uri']) {
(...skipping 10 matching lines...) Expand all
134 136
135 void _validate( 137 void _validate(
136 http.Response response, 138 http.Response response,
137 Uri tokenEndpoint, 139 Uri tokenEndpoint,
138 bool condition, 140 bool condition,
139 String message) { 141 String message) {
140 if (condition) return; 142 if (condition) return;
141 throw new FormatException('Invalid OAuth response for "$tokenEndpoint": ' 143 throw new FormatException('Invalid OAuth response for "$tokenEndpoint": '
142 '$message.\n\n${response.body}'); 144 '$message.\n\n${response.body}');
143 } 145 }
OLDNEW
« no previous file with comments | « pkg/oauth2/lib/src/credentials.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698