|
|
|
@ -17,14 +17,10 @@ class APIError {
|
|
|
|
int? errorType;
|
|
|
|
int? errorType;
|
|
|
|
String? errorMessage;
|
|
|
|
String? errorMessage;
|
|
|
|
int? errorStatusCode;
|
|
|
|
int? errorStatusCode;
|
|
|
|
|
|
|
|
|
|
|
|
APIError(this.errorCode, this.errorMessage, this.errorType, this.errorStatusCode);
|
|
|
|
APIError(this.errorCode, this.errorMessage, this.errorType, this.errorStatusCode);
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
|
|
Map<String, dynamic> toJson() => {'errorCode': errorCode, 'errorMessage': errorMessage, 'errorType': errorType, 'ErrorStatusCode': errorStatusCode};
|
|
|
|
'errorCode': errorCode,
|
|
|
|
|
|
|
|
'errorMessage': errorMessage,
|
|
|
|
|
|
|
|
'errorType': errorType,
|
|
|
|
|
|
|
|
'ErrorStatusCode': errorStatusCode
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
String toString() {
|
|
|
|
@ -46,7 +42,7 @@ APIException _throwAPIException(Response response) {
|
|
|
|
APIError? apiError;
|
|
|
|
APIError? apiError;
|
|
|
|
if (response.body != null && response.body.isNotEmpty) {
|
|
|
|
if (response.body != null && response.body.isNotEmpty) {
|
|
|
|
var jsonError = jsonDecode(response.body);
|
|
|
|
var jsonError = jsonDecode(response.body);
|
|
|
|
apiError = APIError(jsonError['ErrorCode'], jsonError['ErrorMessage'], jsonError['ErrorType'],jsonError['ErrorStatusCode']);
|
|
|
|
apiError = APIError(jsonError['ErrorCode'], jsonError['ErrorMessage'], jsonError['ErrorType'], jsonError['ErrorStatusCode']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return APIException(APIException.BAD_REQUEST, error: apiError);
|
|
|
|
return APIException(APIException.BAD_REQUEST, error: apiError);
|
|
|
|
case 401:
|
|
|
|
case 401:
|
|
|
|
@ -73,7 +69,7 @@ class ApiClient {
|
|
|
|
factory ApiClient() => _instance;
|
|
|
|
factory ApiClient() => _instance;
|
|
|
|
|
|
|
|
|
|
|
|
Future<U> postJsonForObject<T, U>(FactoryConstructor<U> factoryConstructor, String url, T jsonObject,
|
|
|
|
Future<U> postJsonForObject<T, U>(FactoryConstructor<U> factoryConstructor, String url, T jsonObject,
|
|
|
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0, bool isFormData = false}) async {
|
|
|
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0, bool isFormData = false, bool returnJsonData = true}) async {
|
|
|
|
var _headers = {'Accept': 'application/json'};
|
|
|
|
var _headers = {'Accept': 'application/json'};
|
|
|
|
if (headers != null && headers.isNotEmpty) {
|
|
|
|
if (headers != null && headers.isNotEmpty) {
|
|
|
|
_headers.addAll(headers);
|
|
|
|
_headers.addAll(headers);
|
|
|
|
@ -94,7 +90,7 @@ class ApiClient {
|
|
|
|
AppState().setIsAuthenticated = jsonData["IsAuthenticated"];
|
|
|
|
AppState().setIsAuthenticated = jsonData["IsAuthenticated"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (jsonData["ErrorMessage"] == null) {
|
|
|
|
if (jsonData["ErrorMessage"] == null) {
|
|
|
|
return factoryConstructor(jsonData["Data"]);
|
|
|
|
return factoryConstructor(returnJsonData ? jsonData["Data"] : jsonData);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
APIError? apiError;
|
|
|
|
APIError? apiError;
|
|
|
|
apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage'], jsonData['ErrorType'] ?? 0, jsonData['ErrorStatusCode']);
|
|
|
|
apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage'], jsonData['ErrorType'] ?? 0, jsonData['ErrorStatusCode']);
|
|
|
|
@ -147,7 +143,7 @@ class ApiClient {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var response = await _post(Uri.parse(url), body: requestBody, headers: _headers).timeout(Duration(seconds: 120));
|
|
|
|
var response = await _post(Uri.parse(url), body: requestBody, headers: _headers).timeout(Duration(seconds: 120));
|
|
|
|
|
|
|
|
|
|
|
|
if (response. statusCode >= 200 && response.statusCode < 300) {
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
|
|
return response;
|
|
|
|
return response;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw _throwAPIException(response);
|
|
|
|
throw _throwAPIException(response);
|
|
|
|
|