Skip to content

Commit fb8d07f

Browse files
refactor done
1 parent 9b158d7 commit fb8d07f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/Business_Logic/Exceptions/exception_handlers.dart

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ class ExceptionHandlers {
1111
return 'Invalid data format.';
1212
} else if (error is TimeoutException) {
1313
return 'Request timedout.';
14+
} else if (error is BadRequestException) {
15+
return error.message.toString();
16+
} else if (error is UnAuthorizedException) {
17+
return error.message.toString();
18+
} else if (error is NotFoundException) {
19+
return error.message.toString();
20+
} else if (error is FetchDataException) {
21+
return error.message.toString();
1422
} else {
1523
return 'Unknown error occured.';
1624
}

lib/Data/API/base_client.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ class BaseClient {
4646
var responseJson = response.body;
4747
return responseJson;
4848
case 400: //Bad request
49-
throw BadRequestException(response.body).message.toString();
49+
throw BadRequestException(jsonDecode(response.body)['message']);
5050
case 401: //Unauthorized
51-
throw UnAuthorizedException(response.body).message.toString();
51+
throw UnAuthorizedException(jsonDecode(response.body)['message']);
5252
case 403: //Forbidden
53-
throw UnAuthorizedException(response.body).message.toString();
53+
throw UnAuthorizedException(jsonDecode(response.body)['message']);
5454
case 404: //Resource Not Found
55-
throw NotFoundException(response.body).message.toString();
55+
throw NotFoundException(jsonDecode(response.body)['message']);
5656
case 500: //Internal Server Error
5757
default:
5858
throw FetchDataException(

0 commit comments

Comments
 (0)