Skip to content

Commit

Permalink
[fixes] handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mastersam07 committed May 31, 2020
1 parent ff919a0 commit dc1a71e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 53 deletions.
56 changes: 3 additions & 53 deletions lib/networking/api_base_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,6 @@ class ApiBaseHelper {
}
}

//class MangaBaseHelper {
// final String _baseUrl = "https://www.mangaeden.com/api/manga/";
//
// Future<dynamic> get(String url) async {
// print('Api Get, url $url');
// var responseJson;
// try {
// final response = await http.get(_baseUrl + url);
// responseJson = _returnResponse(response);
// } on SocketException {
// print('No net');
// throw FetchDataException('No Internet connection');
// }
// print('api get recieved!');
// return responseJson;
// }
//}

//class ChapterBaseHelper {
// final String _baseUrl = "https://www.mangaeden.com/api/chapter/";
//
// Future<dynamic> get(String url) async {
// print('Api Get, url $url');
// var responseJson;
// try {
// final response = await http.get(_baseUrl + url);
// responseJson = _returnResponse(response);
// } on SocketException {
// print('No net');
// throw FetchDataException('No Internet connection');
// }
// print('api get recieved!');
// return responseJson;
// }
//}

//class PagesBaseHelper {
// final String _baseUrl = "https://cdn.mangaeden.com/mangasimg/";
//
// Future<dynamic> get(String url) async {
// print('Api Get, url $url');
// var responseJson;
// try {
// final response = await http.get(_baseUrl + url);
// responseJson = _returnResponse(response);
// } on SocketException {
// print('No net');
// throw FetchDataException('No Internet connection');
// }
// print('api get recieved!');
// return responseJson;
// }
//}

dynamic _returnResponse(http.Response response) {
switch (response.statusCode) {
Expand All @@ -88,6 +35,9 @@ dynamic _returnResponse(http.Response response) {
case 403:
throw UnauthorisedException(response.body.toString());
case 500:
throw ServerErrorException(response.body.toString());
case 503:
throw ServiceUnavailableException(response.body.toString());
default:
throw FetchDataException(
'Error occured while Communication with Server with StatusCode : ${response.statusCode}');
Expand Down
9 changes: 9 additions & 0 deletions lib/networking/api_exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ class UnauthorisedException extends AppException {
UnauthorisedException([message]) : super(message, "Unauthorised: ");
}

class ServerErrorException extends AppException {
ServerErrorException([message]) : super(message, "internal server error: ");
}

class ServiceUnavailableException extends AppException {
ServiceUnavailableException([message])
: super(message, "Service Unavailable: ");
}

class InvalidInputException extends AppException {
InvalidInputException([String message]) : super(message, "Invalid Input: ");
}

0 comments on commit dc1a71e

Please sign in to comment.