Better response and error handling (json error responses for api, error page response for rendering)