HTTP middleware that catches any panics and serves a proper error response.