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

Cannot add Response to DioException in server.throws #174

Open
fnemethy opened this issue Aug 5, 2024 · 0 comments
Open

Cannot add Response to DioException in server.throws #174

fnemethy opened this issue Aug 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@fnemethy
Copy link

fnemethy commented Aug 5, 2024

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.

@fnemethy fnemethy added the bug Something isn't working label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant