onRequest method
Called when the request is about to be sent.
Implementation
@override
Future<dynamic> onRequest(
RequestOptions options,
RequestInterceptorHandler handler,
) async {
T? currentToken = await token;
try {
if (_shouldRequest != null) {
currentToken = await _tryRequest(options);
//just in case token is refreshing
setToken(currentToken);
}
final headers = currentToken != null
? _tokenHeader(currentToken)
: const <String, String>{};
options.headers.addAll(headers);
handler.next(options);
} on DioError catch (e) {
handler.reject(e);
}
}