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
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
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