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

Reconnecting with a server error does not work #37

Open
wildCherryTO opened this issue Dec 6, 2024 · 2 comments
Open

Reconnecting with a server error does not work #37

wildCherryTO opened this issue Dec 6, 2024 · 2 comments

Comments

@wildCherryTO
Copy link

wildCherryTO commented Dec 6, 2024

At the moment when the server returns an error, reconnection does not work. The problem is in the code section (see below).
The problem is with "return" after calling onError.

File: client.dart

  if (data.statusCode < 200 || data.statusCode >= 300) {
    String responseBody = await data.stream.bytesToString();
    if (onError != null) {
      Map<String, dynamic>? errorDetails;
      try {
        errorDetails = jsonDecode(responseBody);
      } catch (e) {
        errorDetails = {'rawBody': responseBody};
      }

      onError(
        EventFluxException(
          statusCode: data.statusCode,
          reasonPhrase: data.reasonPhrase,
          message: errorDetails.toString().isEmpty
              ? data.reasonPhrase
              : errorDetails.toString(),
        ),
      );
    }
    return;
  }

  if (autoReconnect && data.statusCode != 200) {
    _attemptReconnectIfNeeded(
      _isExplicitDisconnect,
      autoReconnect,
      type,
      url,
      header,
      onSuccessCallback,
      onError: onError,
      onConnectionClose: onConnectionClose,
      httpClient: httpClient,
      body: body,
      files: files,
      multipartRequest: multipartRequest,
    );
    return;
  }
@thedewpoint
Copy link

@wildCherryTO did you find a way around this?

@wildCherryTO
Copy link
Author

Hi! As I wrote above, the problem lies in your code section, where you throw an onError and make a return for any response code less than 200 or more than 300. Thus, you break the logic of reconnection. I bypassed this from my side in my wrapper, as my business demanded. I would be grateful if you would review your code again and correct it. Maybe I didn't do it quite right.

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants