dolanor / rip

REST in peace
BSD 3-Clause "New" or "Revised" License
68 stars 0 forks source link

ErrorCodeBadQArg should use standard status code #3

Closed dolmen closed 5 months ago

dolmen commented 5 months ago

ErrorCodeBadQArg should be 406 or 400, not 499.

dolanor commented 5 months ago

Most of the rip.ErrorCodeXxx have a direct equivalent in http.StatusXxx. For the case where it was more specific to rip or it didn't have a 1-to-1 mapping, I used an arbitrary code that I would then switch to a normal http.StatusXxx code.

In this case, the 499 -> gets mapped to 400. https://github.com/dolanor/rip/blob/main/error.go#L109-L112

The idea was to add extra info in the error type returned. For example, I could use the rip.Error.Source.Header to indicate it was the Accept header ;q=x.y argument that is faulty. I didn't have it at the time I created the error, and now I can see that I didn't set it in my new error type (It's kind of an unfinished business, the error system, for now)

dolmen commented 5 months ago

Well, does ErrorCodeBadQArg need to be public, or is it only for internal use?

dolanor commented 5 months ago

Good point, I don't see any reason for a user of rip to need it. So internal. I'll make it private.