solve looping of dio request due to auth interceptor onError handling

This commit is contained in:
2025-07-11 12:37:08 +05:30
parent 4fcf574a55
commit 9847127e3d

View File

@@ -33,7 +33,14 @@ class AuthInterceptor extends Interceptor {
ErrorInterceptorHandler handler,
) async {
// Handle 401 errors by refreshing token and retrying
if (err.response?.statusCode == 401) {
final response = err.response;
if (response?.statusCode == 401) {
final data = response?.data;
// Only refresh token if error is NOT INCORRECT_TPIN (or similar business error)
if (data is Map && data['error'] == 'INCORRECT_TPIN') {
// Pass the error through, do not retry
return handler.next(err);
}
// On 401, try to get a new token
final token = await _authRepository.getAccessToken();