Closed Noobware1 closed 9 months ago
update is this solution valid? it also passed all test.
That fix looks good to me, if you want to go ahead and submit a PR I'll accept it.
The above fix does the fix the above error but not the original one sadly. can you help me with it. This is the original case.
class AccessTokenInterceptor {
final String crUrl;
final SharedPreferences preferences;
final String PREF_USE_LOCAL_Token;
AccessTokenInterceptor({
required this.crUrl,
required this.preferences,
required this.PREF_USE_LOCAL_Token,
});
Future<Response> intercept(Chain chain) async {
final accessTokenN = await getAccessToken();
final request = newRequestWithAccessToken(chain.request, accessTokenN);
final response = await chain.proceed(request);
if (response.statusCode == HttpStatus.unauthorized) {
final refreshedToken = await getAccessToken(true);
return chain.proceed(
newRequestWithAccessToken(chain.request, refreshedToken),
);
}
return response;
}
Future<AccessToken> getAccessToken([bool force = false]) async {
final String? token =
this.preferences.getString(AccessTokenInterceptor._TOKEN_PREF_KEY);
if (!force && token != null) {
return AccessToken.decode(token);
} else {
final bool useLocalToken = this.preferences.getBool(PREF_USE_LOCAL_Token, false)!;
if (!useLocalToken) {
return refreshAccessToken();
} else {
return refreshAccessToken(false);
}
}
}
Unhandled exception:
OkHttpException(OkHttpException(dart_eval runtime exception: type 'bool' is not a subtype of type '$Value' in type cast
#0 Unbox.run (package:dart_eval/src/eval/runtime/ops/primitives.dart:335:48)
#1 Runtime.bridgeCall (package:dart_eval/src/eval/runtime/runtime.dart:849:12)
#2 EvalFunctionPtr.call (package:dart_eval/src/eval/runtime/function.dart:59:13)
at AccessTokenInterceptor.getAccessToken()
at AccessTokenInterceptor.intercept()
at <anonymous closure>
RUNTIME STATE
=============
Program offset: 1323
Stack sample: [L0: Instance of '$InstanceImpl', L1: false, L2: Instance of '$Completer<dynamic>', L3: Instance of '$SharedPreferences', L4: $"access_token_data", L5: null, L6: Instance of '$null', *L7: null, L8: null, L9: null]
Args sample: []
Call stack: [0, -1, 81, 1260]
TRACE:
1317: PushReturnValue ()
1318: PushNull ()
1319: PushArg (L4)
1320: PushArg (L5)
1321: InvokeDynamic (L3.C105)
1322: PushReturnValue ()
1323: Unbox (L1) <<< EXCEPTION
1324: LogicalNot (L1)
1325: PushNull ()
1326: BoxNull (L8)
, null, null, null, null, null), OkHttpException(dart_eval runtime exception: type 'bool' is not a subtype of type '$Value' in type cast
#0 Unbox.run (package:dart_eval/src/eval/runtime/ops/primitives.dart:335:48)
#1 Runtime.bridgeCall (package:dart_eval/src/eval/runtime/runtime.dart:849:12)
#2 EvalFunctionPtr.call (package:dart_eval/src/eval/runtime/function.dart:59:13)
at AccessTokenInterceptor.getAccessToken()
at AccessTokenInterceptor.intercept()
at <anonymous closure>
Fixed in v0.7.8 (I also fixed this original case you mentioned)
Test case
Error
The current fix I am using tho it's probably wrong