initiateRequest static method
Implementation
static Future<RequestResponse<FrappeResponse?>> initiateRequest(
{required String url,
required HttpMethod method,
String? contentType,
Map<String, dynamic>? headers,
Map<String, dynamic>? data,
Map<String, dynamic>? queryParams,
bool isFrappeResponse = true}) async {
Response<dynamic>? response;
RequestResponse<FrappeResponse?>? r;
try {
response = await Request._httpRequest(url, method, headers,
contentType: contentType, data: data, queryParams: queryParams);
final frappeResponse = _buildFrappeResponse(response, isFrappeResponse);
if ((response.statusCode! / 100).floor() == 2) {
r = RequestResponse.success<FrappeResponse>(frappeResponse);
} else {
final info =
Information(httpCode: response.statusCode, data: response.data);
final errorDetail = ErrorDetail(info: info);
r = RequestResponse.fail(errorDetail);
}
} on DioError catch (err) {
if (err.response != null) {
final frappeResponse =
_buildFrappeResponse(err.response!, isFrappeResponse);
final info = Information(
httpCode: err.response?.statusCode,
data: frappeResponse,
rawError: err);
final errorDetail = ErrorDetail(info: info);
r = RequestResponse.fail(errorDetail);
}
}
if (r != null) {
_messageChecker(r);
_errorChecker(r);
} else {
throw RequestException(
cause: 'No FrappeResponse after initiateRequest',
contentType: contentType,
url: url,
data: data,
queryParams: queryParams,
headers: headers);
}
r.rawResponse = response as Response<String>?;
return r;
}