User Defined Error Responses
User Defined Error Responses
To return an error response as the output of an endpoint cell with a particular HTTP status code, the notebook cell should return a dictionary with a status
key and HTTP status code as its value, as well as an error
object containing a name
with the desired exception name and a message
key with the desired error message.
response = { 'status': 400, 'error': {'name': 'MyException','message': 'Could not compute'}}
response
Alternatively, the endpoint code can raise
an exception and Data Lab Functions will compose the error response. However, the HTTP status would be 500.
HTTP status codes 502, 503, and 504 are reserved and cannot be used in user-defined error responses.