When Bad Things Happen to Good Web Clients (aka Why Did You Send Me a HTTP 400 Error?)Posted: May 2, 2014 | Author: ThomasPowell | Filed under: daily learning | Tags: api, http, rest, status | Leave a comment »
I initially thought that I hadn’t gotten much out of REST API Design Rulebook, mainly because the prescriptions mentioned in the book don’t overlap well with common practice in Rails (or what Rails easily supports).
However, one thing that I developed greater appreciation for was proper use of HTTP status codes. Namely, that HTTP 4xx status codes should indicate that a problem occurred due to something that the client did wrong, regardless of whether improper access or requesting a resource that wasn’t there, and that HTTP 5xx status codes should indicate something unexpected went wrong on the server side.
My challenge came when noticing in test routines that problems that were throwing exceptions were generating 400 errors with stack traces embedded within them. Until I dug deeper into the source of the error, I didn’t realize that errant code was causing the problem, and therefore spent extra time trying to examine my [test] client setup for the source of the problem instead of quickly identifying bad server code as the source of the error.