Handle 500/404, empty Content-Length and requestMaxSize with JSON error messages.

nitpick: it seems to me that the block below can be greaty simplified with a switch statement to set the error value, and then a single call to sendError ?