Updated the rendering to create a response directly with the provided headers and status code.
Added error handling.