Clean up `request` error handling, add docstring