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

Websocket connect, clear error response #103738

Open
raspberry-jenshen opened this issue May 13, 2022 · 4 comments
Open

Websocket connect, clear error response #103738

raspberry-jenshen opened this issue May 13, 2022 · 4 comments
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter dependency: dart:io Issue in 'dart:io' library dependency: dart Dart team may need to help us engine flutter/engine repository. See also e: labels. P3 Issues that are less important to the Flutter project team-engine Owned by Engine team triaged-engine Triaged by Engine team

Comments

@raspberry-jenshen
Copy link

raspberry-jenshen commented May 13, 2022

First of all, want to say thank you all for the impressive and powerful framework!
I like it! Keep rocking!

Issue:

Evvironment

flutter 3.0.0 (latest)
dart 2.17.0 (latest)

Use case

When connecting to WebSocket there is no way to understand why it's failing during updating to WebSocket.

  1. In case the backend is down (500 error)
  2. Connecting via WebSocket.connect
  3. Getting an error
    ` WebSocketException: Connection to 'https://....../sockets#' was not upgraded to web socket

No response code.
No response body.
Just hardcoded error message each time.

What will be if I want to have a different logic based on the server error code?
All existing WebSockets for various platforms has this option.

Proposal

To have a root cause in WebSocketException or even create a separate WebSocketUpgradeException

class WebSocketException implements IOException {
  final String message;
  /// The exception that caused this one, if available.
  final Object? inner;
.....

Improve the error exposing like:

class _WebSocketImpl {
   ..... 
   static Future<WebSocket> connect(....) {
    ......
    Future<WebSocket> error(Exception message) {
        // Flush data.
        response.detachSocket().then((socket) {
          socket.destroy();
        });
        return Future<WebSocket>.error(message, callerStackTrace);
      }

      var connectionHeader = response.headers[HttpHeaders.connectionHeader];
      if (response.statusCode != HttpStatus.switchingProtocols ||
          connectionHeader == null ||
          !connectionHeader.any((value) => value.toLowerCase() == "upgrade") ||
          response.headers.value(HttpHeaders.upgradeHeader)!.toLowerCase() !=
              "websocket") {

        final stringData = await response.transform(utf8.decoder).join();
        final exception = WebSocketUpgradeException(
            message: "Connection to '$uri' was not upgraded to websocket",
            statusCode: response.statusCode,
            data: stringData,
        );
        return error(exception);
      }
  }
}

Thank you in advance!

BTW I haven't found any way how to contribute to the sky_engine package. Cloud you also advise on that?

@darshankawar darshankawar added in triage Presently being triaged by the triage team c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter dependency: dart:io Issue in 'dart:io' library engine flutter/engine repository. See also e: labels. dependency: dart Dart team may need to help us and removed in triage Presently being triaged by the triage team labels May 16, 2022
@chinmaygarde chinmaygarde added the P3 Issues that are less important to the Flutter project label May 16, 2022
@chinmaygarde
Copy link
Member

cc @brianquinlan

@blablabla123-cell
Copy link

Same issue, in case of providing secure websocket connection with JWT. When token is expired server not upgrades the connection but the client (flutter) doenst recieve any message or status codes, error just pops up and cant be handled

@flutter-triage-bot flutter-triage-bot bot added team-engine Owned by Engine team triaged-engine Triaged by Engine team labels Jul 8, 2023
@philos3
Copy link

philos3 commented Jul 9, 2023

Same issue,any updated?

@philos3
Copy link

philos3 commented Jul 10, 2023

dart-lang/sdk#52890

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter dependency: dart:io Issue in 'dart:io' library dependency: dart Dart team may need to help us engine flutter/engine repository. See also e: labels. P3 Issues that are less important to the Flutter project team-engine Owned by Engine team triaged-engine Triaged by Engine team
Projects
None yet
Development

No branches or pull requests

5 participants