doFetch method
Implementation
void doFetch(final VoltronMap requestParams, final JSPromise promise) async {
VoltronHttpRequest httpRequest;
VoltronHttpResponse httpResponse;
try {
httpRequest = await generateHttpRequest(requestParams);
} catch (e) {
promise.reject(e.toString());
return;
}
callBeforeRequestSend(httpRequest);
try {
httpResponse = await sendRequest(httpRequest);
callAfterResponseReceive(httpRequest, httpResponse);
onSuccess(httpRequest, httpResponse, promise);
} catch (e) {
if (e is DioError) {
var resHeaderMap = e.response?.headers.map;
httpResponse = VoltronHttpResponse(
statusCode: e.response?.statusCode ?? VoltronHttpResponse.unknownStatus,
statusMessage: e.response?.statusMessage ?? '',
headerMap: resHeaderMap != null ? normalizeResponseHeader(resHeaderMap) : {},
requestOptions: e.requestOptions,
data: e.response?.data ?? '',
);
} else {
httpResponse = VoltronHttpResponse(
statusCode: VoltronHttpResponse.unknownStatus,
statusMessage: e.toString(),
headerMap: {},
requestOptions: null,
data: '',
);
}
callAfterResponseReceive(httpRequest, httpResponse);
onFailed(httpRequest, httpResponse, promise);
return;
}
}