Skip to content

Cannot add Response to DioException in server.throws #174

@fnemethy

Description

@fnemethy

Description

I would like to simulate a 401 http error with DioAdapter. If I set a response to DioException in onPostrequestHandlerCallback, I gave this exception:

dart:isolate _RawReceivePort._handleMessage
TimeoutException after 0:00:30.000000: Test timed out after 30 seconds. See https://pub.dev/packages/test#timeouts

Steps to reproduce

test(
'When login call failed with 401, returns a InvalidCredentialsException',
() async {
dioAdapter.onPost(
url,
(server) => server.throws(
401,
DioException.badResponse(
statusCode: 401,
requestOptions: RequestOptions(path: url),
response: Response(
statusCode: 401,
requestOptions: RequestOptions(path: url),
),
),
),
data: requestJsonBody
);

  expect(() async => await remoteApi.login(email, password),
      throwsA(InvalidCredentialsException()));
});

Expected behavior

Expect an exception.

System details

0.6.1 http_mock_adapter
Flutter 3.16

Additional context

If I remove the Response part from DioException, it works fine, but cannot simulate my API because I need a response with 401 status code. I tried without badResponse constructor, but still worked wrong. During debugging, the break point was going to dio.post call and after this timeouted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions