OLD | NEW |
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 authorization_exception; | 5 library authorization_exception; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:uri'; | |
9 | 8 |
10 /// An exception raised when OAuth2 authorization fails. | 9 /// An exception raised when OAuth2 authorization fails. |
11 class AuthorizationException implements Exception { | 10 class AuthorizationException implements Exception { |
12 /// The name of the error. Possible names are enumerated in [the spec][]. | 11 /// The name of the error. Possible names are enumerated in [the spec][]. |
13 /// | 12 /// |
14 /// [the spec]: http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-5.2 | 13 /// [the spec]: http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-5.2 |
15 final String error; | 14 final String error; |
16 | 15 |
17 /// The description of the error, provided by the server. Defaults to null. | 16 /// The description of the error, provided by the server. Defaults to null. |
18 final String description; | 17 final String description; |
19 | 18 |
20 /// A URI for a page that describes the error in more detail, provided by the | 19 /// A URI for a page that describes the error in more detail, provided by the |
21 /// server. Defaults to null. | 20 /// server. Defaults to null. |
22 final Uri uri; | 21 final Uri uri; |
23 | 22 |
24 /// Creates an AuthorizationException. | 23 /// Creates an AuthorizationException. |
25 AuthorizationException(this.error, this.description, this.uri); | 24 AuthorizationException(this.error, this.description, this.uri); |
26 | 25 |
27 /// Provides a string description of the AuthorizationException. | 26 /// Provides a string description of the AuthorizationException. |
28 String toString() { | 27 String toString() { |
29 var header = 'OAuth authorization error ($error)'; | 28 var header = 'OAuth authorization error ($error)'; |
30 if (description != null) { | 29 if (description != null) { |
31 header = '$header: $description'; | 30 header = '$header: $description'; |
32 } else if (uri != null) { | 31 } else if (uri != null) { |
33 header = '$header: $uri'; | 32 header = '$header: $uri'; |
34 } | 33 } |
35 return '$header.'; | 34 return '$header.'; |
36 } | 35 } |
37 } | 36 } |
OLD | NEW |