jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.36k stars 1.63k forks source link

[GetConnect] Flutter web error response #1871

Open Petri-Oosthuizen opened 3 years ago

Petri-Oosthuizen commented 3 years ago

Take a basic log in post call:

class LogInApi extends GetConnect {
  Future<Response> login({required String email, password}) => post(
        "https://example.com/users/login",
        {"email": email, "password": password},
      );
}

When this REST call fails (401) the following error response is returned on mobile:

...
bodyString:"{"statusCode":401,"message":"Login failed","details":"Response Error: 401 Unauthorized"}"
request:Request (Instance of 'Request<dynamic>')
statusCode:401
...

The following response is however received in the browser: <error>:<getObject: NoSuchMethodError: The getter 'classRef' was called on null.> The error can however be seen in the browser console: image

gorkemsari commented 2 years ago

Hi,

I'm also facing with same issue. Mobile side it is ok but on Web 401 responses are not catch.

Im not sure that it is about GetX or Flutter itself. Any suggestions?

Petri-Oosthuizen commented 2 years ago

I decided to go with Dio.

gorkemsari commented 2 years ago

So, is there any problem with dio?

Petri-Oosthuizen commented 2 years ago

I haven’t had any.

gorkemsari commented 2 years ago

I have tried it with Dio. Same error occurs on Dio also. status =401 on mobile. error on web. I think it is about Flutter itself.

RaphaelArabeyre commented 2 years ago

Have you tried using request methode instead of post :

Future<Response> login({required String email, password}) => request(
        "https://example.com/users/login",
        "POST",
        query:  <String, String>{"email": email, "password": password},
      );
gorkemsari commented 2 years ago

@RaphaelArabeyre same result