def create_api_error_from_http_exception(e):
 response = e.response
 try:
  explanation = response.json()['message']
 except ValueError:
  explanation = response.content.strip()
 cls = APIError
 if (response.status_code == 404):
  if (explanation and (('No such image' in str(explanation)) or ('not found: does not exist or no read access' in str(explanation)))):
   cls = ImageNotFound
  else:
   cls = NotFound
 raise cls(e, response=response, explanation=explanation)

def create_api_error_from_http_exception ( e ) : response = e . response try : explanation = response . json ( ) [ 'message' ] except ValueError : explanation = response . content . strip ( ) cls = APIError if ( response . status_code == 404 ) : if ( explanation and ( ( 'No such image' in str ( explanation ) ) or ( 'not found: does not exist or no read access' in str ( explanation ) ) ) ) : cls = ImageNotFound else : cls = NotFound raise cls ( e , response = response , explanation = explanation )
create a suitable apierror from requests .