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

Side by Side Diff: pkg/oauth2/lib/src/credentials.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 | « no previous file | pkg/oauth2/lib/src/handle_access_token_response.dart » ('j') | 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 credentials; 5 library credentials;
6 6
7 import 'dart:json'; 7 import 'dart:json';
8 import 'dart:uri'; 8 import 'dart:uri';
9 9
10 import '../../../http/lib/http.dart' as http; 10 import '../../../http/lib/http.dart' as http;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 void validate(bool condition, String message) { 73 void validate(bool condition, String message) {
74 if (condition) return; 74 if (condition) return;
75 throw new FormatException( 75 throw new FormatException(
76 "Failed to load credentials: $message.\n\n$json"); 76 "Failed to load credentials: $message.\n\n$json");
77 } 77 }
78 78
79 var parsed; 79 var parsed;
80 try { 80 try {
81 parsed = JSON.parse(json); 81 parsed = JSON.parse(json);
82 } catch (e) { 82 } catch (e) {
83 // TODO(nweiz): narrow this catch clause once issue 6775 is fixed.
83 validate(false, 'invalid JSON'); 84 validate(false, 'invalid JSON');
84 } 85 }
85 86
86 validate(parsed is Map, 'was not a JSON map'); 87 validate(parsed is Map, 'was not a JSON map');
87 validate(parsed.containsKey('accessToken'), 88 validate(parsed.containsKey('accessToken'),
88 'did not contain required field "accessToken"'); 89 'did not contain required field "accessToken"');
89 validate(parsed['accessToken'] is String, 90 validate(parsed['accessToken'] is String,
90 'required field "accessToken" was not a string, was ' 91 'required field "accessToken" was not a string, was '
91 '${parsed["accessToken"]}'); 92 '${parsed["accessToken"]}');
92 93
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 if (credentials.refreshToken != null) return credentials; 182 if (credentials.refreshToken != null) return credentials;
182 return new Credentials( 183 return new Credentials(
183 credentials.accessToken, 184 credentials.accessToken,
184 this.refreshToken, 185 this.refreshToken,
185 credentials.tokenEndpoint, 186 credentials.tokenEndpoint,
186 credentials.scopes, 187 credentials.scopes,
187 credentials.expiration); 188 credentials.expiration);
188 }); 189 });
189 } 190 }
190 } 191 }
OLDNEW
« no previous file with comments | « no previous file | pkg/oauth2/lib/src/handle_access_token_response.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698