Skip to content

add path information to body deserialization failure - #598

Merged
ahl merged 2 commits into
mainfrom
path-to
Mar 9, 2023
Merged

ahl merged 2 commits into
mainfrom
path-to

Conversation

@ahl

@ahl ahl commented Feb 28, 2023

Copy link
Copy Markdown
Collaborator

@ahl
ahl requested a review from davepacheco February 28, 2023 00:41
serde_path_to_error::deserialize(jd).map_err(|e| {
HttpError::for_bad_request(
None,
format!("unable to parse JSON body: {}", e),

@david-crespo david-crespo Feb 28, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we're going this far, I think "unable to parse JSON body" should be changed as well. IMO from the point of view of an API consumer, the fact that the error arises as a failure to parse is a bit of an implementation detail. From the API's point of view the point is that it's an invalid body, just as negative disk size would be invalid, even though it's technically parseable.

I'm not sure drawing a distinction between the two is useful to the API consumer, or least if it is, where we're drawing the line is not where I would draw it. As in: to me, I'd expect to get an error about unparseable JSON if what I sent was not JSON at all. The "unable to parse" error for something that's technically JSON but not what the API wanted is confusing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I see you point. What would you prefer to see here?

@david-crespo david-crespo Feb 28, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

“Invalid request body: …” seems ok. I think in the case where it’s not even JSON, you’ll get a reasonably suggestive message after that about “expected { at line 1”, right? It might still be helpful to say “could not parse JSON” in that case.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It seems like if it's not JSON at all, you do want to mention that, right? It might not be obvious from whatever's expected ("expected ','") that the problem is it's not JSON at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants