Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter Web: Generic ClientException on 401/403 Prevents Effective Retry Logic in shouldAttemptRetryOnResponse #152

Open
NachiketaVadera opened this issue Dec 10, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@NachiketaVadera
Copy link

GitHub Issue: Generic ClientException on 401/403 Prevents Effective Retry Logic

When using http_interceptor with a custom RetryPolicy, the retry logic does not work correctly for 401 and 403 HTTP status codes. The issue arises because the client throws a generic ClientException for these responses instead of allowing the response object to flow through. This causes the logic to be handled by shouldAttemptRetryOnException rather than shouldAttemptRetryOnResponse.

The ClientException provides no meaningful details about the HTTP response (e.g., status code or headers), making it impossible to determine if the request should be retried. This severely limits the ability to implement token refresh or retry policies based on specific HTTP status codes.

Steps to Reproduce:

  1. Create a custom RetryPolicy class and implement shouldAttemptRetryOnResponse to handle 401/403 responses.
  2. Make an HTTP request that returns a 401 or 403 response.
  3. Observe that _attemptRequest throws a ClientException instead of passing the response to shouldAttemptRetryOnResponse.
  4. In shouldAttemptRetryOnException, the Exception object lacks sufficient details to identify the HTTP status code.

Expected Behavior:
The library should allow responses with 401 and 403 status codes to be passed to shouldAttemptRetryOnResponse for appropriate handling.

Actual Behavior:
The library throws a generic ClientException with no meaningful information, forcing retry logic to rely on incomplete data in shouldAttemptRetryOnException.

Example:

class ExpiredTokenRetryPolicy extends RetryPolicy {
  @override
  Future<bool> shouldAttemptRetryOnResponse(BaseResponse response) async {
    if (response.statusCode == 401) {

      return true;
    }

    return false;
  }
}

final client = InterceptedHttp.build(
    interceptors: [AuthHeaderInterceptorContract()],
    retryPolicy: ExpiredTokenRetryPolicy(),
);
  
client.get('...'); // throws client exception

Environment:

  • Flutter version: 3.24.5
  • http_interceptor version: 2.0.0
  • Platform: Web

Additional Context:
The generic ClientException in this case provides an error like "XMLHttpRequest error," which is not useful for making retry decisions.

@NachiketaVadera NachiketaVadera added the bug Something isn't working label Dec 10, 2024
@CodingAleCR
Copy link
Owner

@NachiketaVadera Just wanted to acknowledge that I saw this, just haven't had time to look into it. Thank you for contributing to improving the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants