Create a suitable APIError from requests.exceptions.HTTPError.
(e)
| 20 | |
| 21 | |
| 22 | def create_api_error_from_http_exception(e): |
| 23 | """ |
| 24 | Create a suitable APIError from requests.exceptions.HTTPError. |
| 25 | """ |
| 26 | response = e.response |
| 27 | try: |
| 28 | explanation = response.json()['message'] |
| 29 | except ValueError: |
| 30 | explanation = (response.text or '').strip() |
| 31 | cls = APIError |
| 32 | if response.status_code == 404: |
| 33 | explanation_msg = (explanation or '').lower() |
| 34 | if any(fragment in explanation_msg |
| 35 | for fragment in _image_not_found_explanation_fragments): |
| 36 | cls = ImageNotFound |
| 37 | else: |
| 38 | cls = NotFound |
| 39 | raise cls(e, response=response, explanation=explanation) from e |
| 40 | |
| 41 | |
| 42 | class APIError(requests.exceptions.HTTPError, DockerException): |
no outgoing calls