UUIDs and the battle between 400 vs 404

So I’m using a uuid in place of a standard integer for my primary key on one of my schemas.

IE:

 @primary_key {:id, :binary_id, autogenerate: true}

I also currently use that as my primary way to query the records ie:
https://polymorphic.productions/snapshots/683adaf5-f98c-4e90-b1a2-b90ec1c51e78/

I get two flavors of not found depending on if the param is a valid binary_id or not.
In the case of the param key still being considered a binary_id I will get a 404 (not found) other wise I get 400 bad request.

I take issue with the 400 because it has little consequence to my end users and adds little to inform them that its really just a bad url. It will also raise an exception that I currently am not ignoring as I do my 404s.

In short my 400’s are annoying. Has anyone else ran into this all be it small but annoying issue?

Whats your thoughts on this?

1 Like

A 400 seems perfectly legitimate here, that’s the HTTP request code for the User sent malformed/bad request data for the given endpoint. A 404 means the request was valid but just that the thing did not exist.

They will also be caused at different places in your code as well, the 404 probably coming from an ecto changeset or a Repo bang function, and the 400 probably is a precheck somewhere. :slight_smile:

You can always return whatever code you wish to as well if you wish to massage anything. :slight_smile:

3 Likes