sendRequest<T> method
Implementation
Future<T> sendRequest<T>(SendContext info) async {
int statusCode = -1;
HttpClientResponse res;
try {
var req = await createRequest(info);
if (urlFilter != null) {
urlFilter!(req.uri.toString());
}
res = await req.close();
statusCode = res.statusCode;
} on Exception catch (e) {
Log.debug("sendRequest() createRequest: $e");
return await handleError(null, e);
}
try {
var response = await createResponse(res, info);
return response;
} on Exception catch (e) {
var debug = Log.isDebugEnabled();
if (debug) Log.debug("sendRequest(): statusCode:$statusCode, $e");
if (statusCode == 401) {
var hasRefreshTokenCookie = cookies!.any((x) => x.name == "ss-reftok");
if (refreshToken != null || useTokenCookie || hasRefreshTokenCookie) {
var jwtRequest = GetAccessToken(refreshToken: this.refreshToken);
var url = refreshTokenUri ?? createUrlFromDto("POST", jwtRequest);
var jwtInfo = SendContext(
method: "POST", request: jwtRequest, args: null, url: url);
try {
var jwtReq = await createRequest(jwtInfo);
var jwtRes = await jwtReq.close();
var jwtResponse =
await createResponse<GetAccessTokenResponse>(jwtRes, jwtInfo);
bearerToken = jwtResponse!.accessToken;
if (debug) Log.debug("sendRequest(): bearerToken refreshed");
return await _resendRequest<T>(info);
} on Exception catch (jwtEx) {
if (debug) Log.debug("sendRequest(): jwtEx: $jwtEx");
return await handleError(
res, jwtEx, WebServiceExceptionType.RefreshTokenException);
}
}
if (onAuthenticationRequired != null) {
await onAuthenticationRequired!();
return await _resendRequest<T>(info);
}
}
return await handleError(res, e);
}
}