Skip to content

Reconnecting with a server error does not work #37

@wildCherryTO

Description

@wildCherryTO

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;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions