Repository navigation
Conversation
Several places used the same
```
if reply was not successful {
err out
}
decode reply
```
pattern. We collect it in `try_decode` to dedupe the success checking and
a more compact code base.
Having static media types as static strings is prone to typos. So we convert them to constants, to make typos visible at compile time.
Deduping content type checking gives similar experience across all uses. It for example removes differences for responses having two `Content-Type` headers.
This makes it more obvious for users where things went wrong.
somechris
commented
Nov 8, 2026
| .send(self.request(Method::POST, url).json(request)) | ||
| .await?; | ||
| if matches!(reply.status, StatusCode::OK | StatusCode::CREATED) { | ||
| return self.decode(&reply.body); |
Author
There was a problem hiding this comment.
Not switching to try_decode here, as the guard is not a plain is_success.
If that's a development relict, it could of course switch to try_decode too.
| async fn get(&self, url: Url) -> Result<serde_json::Value, ApiError> { | ||
| let reply = self.read(url, "application/json").await?; | ||
| let reply = self.read(url, MEDIA_TYPE_JSON).await?; | ||
| self.decode(&reply.body) |
Author
There was a problem hiding this comment.
No try_decode here, as a successful read asserts that the request succeeded.
Can be treated as micro-optimization and switched to try_decode nonetheless.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.