class MarathonError(Exception):
    pass


class MarathonHttpError(MarathonError):

    def __init__(self, response):
        """
        :param :class:`requests.Response` response: HTTP response
        """
        content = response.json()
        self.status_code = response.status_code
        self.error_message = content.get('message')
        super(MarathonHttpError, self).__init__(self.__str__())

    def __repr__(self):
        return 'MarathonHttpError: HTTP %s returned with message, "%s"' % \
               (self.status_code, self.error_message)

    def __str__(self):
        return self.__repr__()


class NotFoundError(MarathonHttpError):
    pass


class InternalServerError(MarathonHttpError):
    pass


class InvalidChoiceError(MarathonError):

    def __init__(self, param, value, options):
        super(InvalidChoiceError, self).__init__(
            'Invalid choice "{value}" for param "{param}". Must be one of {options}'.format(
                param=param, value=value, options=options
            )
        )

class MarathonError(Exception):
    pass


class MarathonHttpError(MarathonError):

    def __init__(self, response):
        """
        :param :class:`requests.Response` response: HTTP response
        """
        self.error_message = response.reason or ''
        if response.content:
            content = response.json()
            self.error_message = content.get('message', self.error_message)
        self.status_code = response.status_code
        super(MarathonHttpError, self).__init__(self.__str__())

    def __repr__(self):
        return 'MarathonHttpError: HTTP %s returned with message, "%s"' % \
               (self.status_code, self.error_message)

    def __str__(self):
        return self.__repr__()


class NotFoundError(MarathonHttpError):
    pass


class InternalServerError(MarathonHttpError):
    pass


class InvalidChoiceError(MarathonError):

    def __init__(self, param, value, options):
        super(InvalidChoiceError, self).__init__(
            'Invalid choice "{value}" for param "{param}". Must be one of {options}'.format(
                param=param, value=value, options=options
            )
        )

Handle HTTP errors without content graceful
Handle HTTP errors without content graceful

HTTP errors like 503 do not have a content set by Marathon. Try to use
the response reason string as an alternative error message.

  class MarathonError(Exception):
      pass
  
  
  class MarathonHttpError(MarathonError):
  
      def __init__(self, response):
          """
          :param :class:`requests.Response` response: HTTP response
          """
+         self.error_message = response.reason or ''
+         if response.content:
-         content = response.json()
+             content = response.json()
+             self.error_message = content.get('message', self.error_message)
          self.status_code = response.status_code
-         self.error_message = content.get('message')
          super(MarathonHttpError, self).__init__(self.__str__())
  
      def __repr__(self):
          return 'MarathonHttpError: HTTP %s returned with message, "%s"' % \
                 (self.status_code, self.error_message)
  
      def __str__(self):
          return self.__repr__()
  
  
  class NotFoundError(MarathonHttpError):
      pass
  
  
  class InternalServerError(MarathonHttpError):
      pass
  
  
  class InvalidChoiceError(MarathonError):
  
      def __init__(self, param, value, options):
          super(InvalidChoiceError, self).__init__(
              'Invalid choice "{value}" for param "{param}". Must be one of {options}'.format(
                  param=param, value=value, options=options
              )
          )
  
Handle HTTP errors without content graceful
## Code Before:
class MarathonError(Exception):
    pass


class MarathonHttpError(MarathonError):

    def __init__(self, response):
        """
        :param :class:`requests.Response` response: HTTP response
        """
        content = response.json()
        self.status_code = response.status_code
        self.error_message = content.get('message')
        super(MarathonHttpError, self).__init__(self.__str__())

    def __repr__(self):
        return 'MarathonHttpError: HTTP %s returned with message, "%s"' % \
               (self.status_code, self.error_message)

    def __str__(self):
        return self.__repr__()


class NotFoundError(MarathonHttpError):
    pass


class InternalServerError(MarathonHttpError):
    pass


class InvalidChoiceError(MarathonError):

    def __init__(self, param, value, options):
        super(InvalidChoiceError, self).__init__(
            'Invalid choice "{value}" for param "{param}". Must be one of {options}'.format(
                param=param, value=value, options=options
            )
        )

## Instruction:
Handle HTTP errors without content graceful
## Code After:
class MarathonError(Exception):
    pass


class MarathonHttpError(MarathonError):

    def __init__(self, response):
        """
        :param :class:`requests.Response` response: HTTP response
        """
        self.error_message = response.reason or ''
        if response.content:
            content = response.json()
            self.error_message = content.get('message', self.error_message)
        self.status_code = response.status_code
        super(MarathonHttpError, self).__init__(self.__str__())

    def __repr__(self):
        return 'MarathonHttpError: HTTP %s returned with message, "%s"' % \
               (self.status_code, self.error_message)

    def __str__(self):
        return self.__repr__()


class NotFoundError(MarathonHttpError):
    pass


class InternalServerError(MarathonHttpError):
    pass


class InvalidChoiceError(MarathonError):

    def __init__(self, param, value, options):
        super(InvalidChoiceError, self).__init__(
            'Invalid choice "{value}" for param "{param}". Must be one of {options}'.format(
                param=param, value=value, options=options
            )
        )
