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

Provide better experience when POSTing an empty body on an endpoint that only has optional body params #635

Open
zephraph opened this issue Apr 4, 2023 · 0 comments

Comments

@zephraph
Copy link
Contributor

zephraph commented Apr 4, 2023

Recently we added /v1/disks/{disk}/finalize to Oxide's API which has a post body of { snapshot_name: Option<Name> }. One might assume that you could simply not specify a POST body when calling the endpoint and it would be handled correctly. That assumption is wrong. Currently the empty string of the POST gets passed to serde which gives us a lovely error of unable to parse JSON body: EOF while parsing a value at line 1 column 0. Now if you know that serde is responsible for parsing the POST body and you know that an empty string is invalid JSON then this error makes complete sense. I do not expect consumers of our API (or other APIs using dropshot) to have that knowledge.

We have a few options here.

  1. We could make an update such that dropshot understands that a Body can be optional. This is the ideal implementation imo because it just works™. The best error is no error.
  2. We just improve the error message just to inform folks that the body can't be empty. This is likely much easier and a perfectly fine bridge between where we are and where we want to be.
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

No branches or pull requests

1 participant