Merge branch 'development_sikander' into 'master'

api structure improvement.

See merge request mirza.shafique/mohem_flutter_app!11
merge-requests/1/merge
Sikander Saleem 3 years ago
commit a678a0e26a

@ -10,8 +10,8 @@ import 'package:mohem_flutter_app/exceptions/api_exception.dart';
typedef FactoryConstructor<U> = U Function(dynamic); typedef FactoryConstructor<U> = U Function(dynamic);
class APIError { class APIError {
int errorCode; int? errorCode;
String errorMessage; String? errorMessage;
APIError(this.errorCode, this.errorMessage); APIError(this.errorCode, this.errorMessage);
@ -74,18 +74,22 @@ class ApiClient {
print("body:$jsonObject"); print("body:$jsonObject");
} }
var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: _headers, retryTimes: retryTimes); var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: _headers, retryTimes: retryTimes);
// try { try {
var jsonData = jsonDecode(response.body); var jsonData = jsonDecode(response.body);
if (jsonData["ErrorMessage"] != null) { if (jsonData["ErrorMessage"] == null) {
return factoryConstructor(jsonData); return factoryConstructor(jsonData);
} else { } else {
throw _throwAPIException(response); APIError? apiError;
apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorMessage']);
throw APIException(APIException.BAD_REQUEST, error: apiError);
} }
// } catch (ex) { } catch (ex) {
// print(response.body); if (ex is APIException) {
// print(ex); rethrow;
// throw APIException(APIException.BAD_RESPONSE_FORMAT, arguments: ex); } else {
// } throw APIException(APIException.BAD_RESPONSE_FORMAT, arguments: ex);
}
}
} }
Future<Response> postJsonForResponse<T>(String url, T jsonObject, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async { Future<Response> postJsonForResponse<T>(String url, T jsonObject, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {

Loading…
Cancel
Save