A wrapper around Response objects for HTTP error codes. :param response: requests Response object :type response: Response
| 34 | |
| 35 | |
| 36 | class MesosHTTPException(MesosException): |
| 37 | """ |
| 38 | A wrapper around Response objects for HTTP error codes. |
| 39 | |
| 40 | :param response: requests Response object |
| 41 | :type response: Response |
| 42 | """ |
| 43 | STATUS_CODE = None |
| 44 | |
| 45 | def __init__(self, response): |
| 46 | super(MesosHTTPException, self).__init__() |
| 47 | self.response = response |
| 48 | |
| 49 | def status(self): |
| 50 | """ |
| 51 | Return status code from response. |
| 52 | |
| 53 | :return: status code |
| 54 | :rtype: int |
| 55 | """ |
| 56 | if self.STATUS_CODE is None: |
| 57 | return self.response.status_code |
| 58 | return self.STATUS_CODE |
| 59 | |
| 60 | def __str__(self): |
| 61 | return "The url '{url}' returned HTTP {status_code}: {text}"\ |
| 62 | .format(url=self.response.request.url, |
| 63 | status_code=self.response.status_code, |
| 64 | text=self.response.text) |
| 65 | |
| 66 | |
| 67 | class MesosAuthenticationException(MesosHTTPException): |