示例#1
0
 def message_from_error(self, exc):
     if isinstance(exc, ApiUnauthorized):
         return ERR_UNAUTHORIZED
     elif isinstance(exc, ApiHostError):
         return exc.text
     elif isinstance(exc, UnsupportedResponseType):
         return ERR_UNSUPPORTED_RESPONSE_TYPE.format(content_type=exc.content_type)
     elif isinstance(exc, ApiError):
         if exc.json:
             msg = self.error_message_from_json(exc.json) or "unknown error"
         else:
             msg = getattr(exc, "text", "unknown error")
         return f"Error Communicating with {self.title} (HTTP {exc.code}): {msg}"
     else:
         return ERR_INTERNAL
示例#2
0
文件: base.py 项目: waterdrops/sentry
 def message_from_error(self, exc: ApiError) -> str:
     if isinstance(exc, ApiUnauthorized):
         return ERR_UNAUTHORIZED
     elif isinstance(exc, ApiHostError):
         # Explicitly typing to satisfy mypy.
         message: str = exc.text
         return message
     elif isinstance(exc, UnsupportedResponseType):
         return ERR_UNSUPPORTED_RESPONSE_TYPE.format(content_type=exc.content_type)
     elif isinstance(exc, ApiError):
         if exc.json:
             msg = self.error_message_from_json(exc.json) or "unknown error"
         else:
             msg = "unknown error"
         return f"Error Communicating with {self.model.get_provider().name} (HTTP {exc.code}): {msg}"
     else:
         return ERR_INTERNAL
示例#3
0
 def message_from_error(self, exc):
     if isinstance(exc, ApiUnauthorized):
         return ERR_UNAUTHORIZED
     elif isinstance(exc, ApiHostError):
         return exc.text
     elif isinstance(exc, UnsupportedResponseType):
         return ERR_UNSUPPORTED_RESPONSE_TYPE.format(content_type=exc.content_type)
     elif isinstance(exc, ApiError):
         if exc.json:
             msg = self.error_message_from_json(exc.json) or "unknown error"
         else:
             msg = "unknown error"
         return "Error Communicating with %s (HTTP %s): %s" % (
             self.model.get_provider().name,
             exc.code,
             msg,
         )
     else:
         return ERR_INTERNAL