Raises a native error from an HTTP response if the response indicates an error return UnknownAPIError (message =error_message ) def raise_on_frameio_error (response, expected_status ) : """ status_code, default = None ) if error_type is not None : return error_type ( ) # Otherwise we are going to return an `UnknownAPIError` to signal that we # encoutnered an error from Frame.io's backend servers, but do not know the # message and/or status code. get (error_message, default = None ) if error_type is not None : return error_type ( ) # If not, try to do a lookup by error code.Įrror_type = ERROR_STATUS_MAP. get ( "message", default = None ) def _c2c_error_type_from_response (response ) : """Ĭonverts a bad HTTP response into an error.Įrror_message = _c2c_extract_error_message (response ) # try to do a lookup of the error type by message.Įrror_type = ERROR_MESSAGE_MAP. get ( "error", default = None ) if message is not None : return message json ( ) except JSONDecodeError : return None # Try the simple error schema first. """ # Try to decode the payload, if it is not JSON return `None` try : Gets the error message from an error payload. # Dict of known error codes: native errors.ĮRROR_STATUS_MAP = def _c2c_extract_error_message (response ) : """ If you get an unexpected HTTP status, please let us know! Similarly, 404: Not Found may be produced by services / hardware between Frame.io and our backend, even though it is a 4XX status. 500 errors mean that something unexpected went wrong in the inner workings of our server code.
One notable exception is 500 - which is an INTERNAL SERVER ERROR.
In general, if an error is not a 4XX error, that error did not originate on our end, but somewhere between your device and our application. Most API errors will be in the 4XX range (400-499). If a status code is greater than 399, then it is an error status code. You can either explicitly check for the correct status, or more generally check that the status code is between 200-299. You can read more about HTTP code meanings in this great resource from Mozilla, or if you prefer feline-based learning frameworks, this page was made for you.Įach Frame.io API endpoint will have an expected status code on a success - generally 200: OK, 201: Created, or 204: No Content. HTTP status codes are a standard set of numbers used to communicate the overall result of an HTTP request.