onError method
Called when an exception was occurred during the request.
Implementation
@override
// ignore: deprecated_member_use
void onError(DioError err, ErrorInterceptorHandler handler) {
EventTracker()
.addEvent(getEvent(Events.RESPONSE_VALIDATION, EventTracker.sourceSdk));
if (err.response != null) {
var response = err.response!;
var responseHeaders = response.headers.map;
// store set-cookie
responseHeaders.forEach((key, value) {
if (key.toLowerCase() == "set-cookie") {
setDataDomeCookie(value.first);
}
});
var ddHeaders =
(responseHeaders.keys.any((key) => key.toLowerCase() == 'x-dd-b') ||
responseHeaders.keys
.any((key) => key.toLowerCase() == 'x-sf-cc-x-dd-b'));
var code = response.statusCode;
if ((code == 401 || code == 403) && (ddHeaders)) {
//blocked by datadome
failedRequests.add(RetriableRequest(dio, err, handler));
if (isDisplayed) {
return;
}
ResponsePage? responsePage = responsePageFromResponse(response);
// set the DataDome cookie value (cid) to datadomeCookie variable
getDataDomeCookie().then((value) =>
CaptchaPage.datadomeCookie = value.split("datadome=")[1]);
if (context != null && responsePage != null) {
_showChallenge(context!, responsePage, (String cookie) {
didResolveCaptcha(cookie);
});
} else {
// calling `DataDomeInterceptor.withCallback` the customer handle the captcha display and dismissal
Widget widget = new CaptchaPage(
responsePage: responsePage,
onCaptchaResolved: (String cookie) {
didResolveCaptcha(cookie);
});
if (onCaptchaDisplay != null) {
onCaptchaDisplay!(widget);
}
}
return;
}
} else {
DataDomeLogger.error("Null DioError response info");
return;
}
super.onError(err, handler);
}