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