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

Improve exception message for DioException.badResponse #1998

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

ueman
Copy link
Contributor

@ueman ueman commented Oct 16, 2023

Since we receive a lot of issues around the topic of status code, I think we should improve message of it. So I've made it more descriptinve and actionable.

New Pull Request Checklist

  • I have read the Documentation
  • I have searched for a similar pull request in the project and found none
  • I have updated this branch with the latest main branch to avoid conflicts (via merge from master or rebase)
  • I have added the required tests to prove the fix/feature I'm adding
  • I have updated the documentation (if necessary)
  • I have run the tests without failures
  • I have updated the CHANGELOG.md in the corresponding package

Additional context and info (if any)

@ueman ueman marked this pull request as ready for review October 16, 2023 17:12
@ueman ueman requested a review from a team as a code owner October 16, 2023 17:12
@kuhnroyal
Copy link
Member

Nice, just think we should still print the actual status code somewhere.
Something like Server error (500) - ...

@ueman
Copy link
Contributor Author

ueman commented Oct 16, 2023

Nice, just think we should still print the actual status code somewhere. Something like Server error (500) - ...

It does right in the first line of the exception message:
'This exception was thrown because the response has a status code of $statusCode '
or are you referring to the message describing the status code range?

@kuhnroyal
Copy link
Member

My bad...

@kuhnroyal kuhnroyal added the p: dio Targeting `dio` package label Oct 16, 2023
@ueman ueman added this pull request to the merge queue Oct 16, 2023
Merged via the queue into main with commit a395cad Oct 16, 2023
34 checks passed
@ueman ueman deleted the improve-exception-messages branch October 16, 2023 17:26
Copy link
Member

@AlexV525 AlexV525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late review comments

} else {
message =
'A response with a status code that is not within the range of inclusive 100 to exclusive 600'
'is a non-standard response, possibly due to the server\'s software.';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be a duplicated dot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I rather want the message to be helpful than concise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I rather want the message to be helpful than concise.

Hmm, what I mean is the last dot of possibly due to the server\'s software. might be redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, yeah, that might be redundant, but this message is aimed at people who are not yet that knowledgeable of the HTTP spec and so on. So I think it's a rather helpful addition, even if it might seem superfluous for us knowledgeable people.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DioException [bad response]: This exception was thrown because the response has a status code of 0 and RequestOptions.validateStatus was configured to throw for this status code.
The status code of 0 has the following meaning: "A response with a status code that is not within the range of inclusive 100 to exclusive 600is a non-standard response, possibly due to the server's software."
.Read more about status codes at https://developer.mozilla.org/en-US/docs/Web/HTTP/Status

Here it should be "server's software.".\nRead more, right? It's "server's software."\n.Read more currently.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which made that dot redundant

/// Because of [ValidateStatus] we need to consider all status codes when
/// creating a [DioException.badResponse].
static String _badResponseExceptionMessage(int statusCode) {
var message = '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used to write final String message if it's declared in every single flow.

'is a non-standard response, possibly due to the server\'s software.';
}

return ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe StringBuffer would be a good choice at here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really aware of the benefits of a StringBuffer. Can you explain why it would improve this code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really aware of the benefits of a StringBuffer. Can you explain why it would improve this code?

You just don't have to constantly write \n then.

@ueman
Copy link
Contributor Author

ueman commented Oct 17, 2023

@AlexV525 I plan to do another round of exception message improvements for the other exceptions. I'll incorporate your feedback in that PR, okay?

@AlexV525
Copy link
Member

@AlexV525 I plan to do another round of exception message improvements for the other exceptions. I'll incorporate your feedback in that PR, okay?

Yeah sure. I'm available now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p: dio Targeting `dio` package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants