Skip to content

Commit

Permalink
docs: update exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tnc1997 committed Feb 7, 2021
1 parent e0eb18e commit 55b5962
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/src/exceptions/client_exception.dart
Expand Up @@ -2,28 +2,39 @@ import 'package:tfl_api_client/src/extensions/response_extensions.dart';
import 'package:http/http.dart';

class ClientException implements Exception {
final String? message;
/// The message of the exception.
final String message;

/// The uri of the request if applicable.
final Uri? uri;

/// The status code of the response if applicable.
final int? statusCode;

/// The reason phrase of the response if applicable.
final String? reasonPhrase;

/// Constructs a [ClientException].
ClientException({
this.message,
required this.message,
this.uri,
this.statusCode,
this.reasonPhrase,
});

/// Constructs a [ClientException] from the [response].
ClientException.fromResponse(Response response)
: message = response.body,
uri = response.request?.url,
statusCode = response.statusCode,
reasonPhrase = response.reasonPhrase;

@override
String toString() =>
message != null ? 'ClientException: $message' : 'ClientException';
String toString() => 'ClientException: $message';

/// Checks that the [response] has a success status code.
///
/// Throws a [ClientException] if the [response] does not have a success status code.
static Response checkIsSuccessStatusCode(Response response) {
if (!response.isSuccessStatusCode) {
throw ClientException.fromResponse(response);
Expand Down

0 comments on commit 55b5962

Please sign in to comment.