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

Invalid exception is thrown when server is unavailable #277

Closed
miroljub1995 opened this issue Jun 1, 2023 · 5 comments
Closed

Invalid exception is thrown when server is unavailable #277

miroljub1995 opened this issue Jun 1, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@miroljub1995
Copy link

Describe the bug
If server is currently unavailable (503 status), we receive some weird exception <' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
Looks like it is missing response.EnsureSuccessStatusCode() before this line:

return await response.Content.ReadFromJsonAsync<TResponse>(cancellationToken: cancellationToken) ?? throw new InvalidOperationException();

Result
Error: <' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.

Expected behavior
Let dotnet throw HttpRequestException so we can implement retry logic.

Desktop:

  • OS: Ubuntu
  • Language: c#
  • Dotnet version: 7
  • Lib version: 6.8.4
@kayhantolga kayhantolga self-assigned this Jun 1, 2023
@kayhantolga kayhantolga added the bug Something isn't working label Jun 1, 2023
@kayhantolga kayhantolga added this to the 7.1.0 milestone Jun 1, 2023
@winzig
Copy link

winzig commented Jun 1, 2023

Wonder if you're seeing the same basic issue as I am: #266

@miroljub1995
Copy link
Author

Yeah, it can be if status is not 2xx.

@Artein
Copy link

Artein commented Jun 16, 2023

I started to receive such exceptions too. Initially thought it is something with my requests, cause I am expecting a response in JSON format. But eventually found this thread. As a workaround, I can catch that exception and retry my request.

Edit: Just realized it is planned for 7.1.0. Waiting for this release

@kayhantolga kayhantolga modified the milestones: 7.1.0, 7.2.1 Jul 25, 2023
@kayhantolga kayhantolga added the Ready for next version This issue solved and waiting for next release label Oct 6, 2023
@kayhantolga kayhantolga reopened this Oct 19, 2023
@kayhantolga
Copy link
Member

kayhantolga commented Oct 19, 2023

Using response.EnsureSuccessStatusCode() is causing additional trouble. I am planning to implement specific logic for handling 503 cases. Does anyone know how to get a 503 response from the server or has anyone saved the incoming HTML response?

@kayhantolga
Copy link
Member

Moved to #447

@kayhantolga kayhantolga removed this from the 8.0.3 milestone Apr 10, 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

4 participants