Error handling in PyGithub is done with exceptions. This class is the base of all exceptions raised by PyGithub (but :class:`github.GithubException.BadAttributeException`). Some other types of exceptions might be raised by underlying libraries, for example for network-related issues.
| 45 | |
| 46 | |
| 47 | class GithubException(Exception): |
| 48 | """ |
| 49 | Error handling in PyGithub is done with exceptions. This class is the base of all exceptions raised by PyGithub |
| 50 | (but :class:`github.GithubException.BadAttributeException`). |
| 51 | |
| 52 | Some other types of exceptions might be raised by underlying libraries, for example for network-related issues. |
| 53 | |
| 54 | """ |
| 55 | |
| 56 | def __init__( |
| 57 | self, |
| 58 | status: int, |
| 59 | data: Any = None, |
| 60 | headers: dict[str, str] | None = None, |
| 61 | message: str | None = None, |
| 62 | ): |
| 63 | super().__init__() |
| 64 | self.__status = status |
| 65 | self.__data = data |
| 66 | self.__headers = headers |
| 67 | self.__message = message |
| 68 | self.args = (status, data, headers, message) |
| 69 | |
| 70 | @property |
| 71 | def message(self) -> str | None: |
| 72 | return self.__message |
| 73 | |
| 74 | @property |
| 75 | def status(self) -> int: |
| 76 | """ |
| 77 | The status returned by the Github API. |
| 78 | """ |
| 79 | return self.__status |
| 80 | |
| 81 | @property |
| 82 | def data(self) -> Any: |
| 83 | """ |
| 84 | The (decoded) data returned by the Github API. |
| 85 | """ |
| 86 | return self.__data |
| 87 | |
| 88 | @property |
| 89 | def headers(self) -> dict[str, str] | None: |
| 90 | """ |
| 91 | The headers returned by the Github API. |
| 92 | """ |
| 93 | return self.__headers |
| 94 | |
| 95 | def __repr__(self) -> str: |
| 96 | return f"{self.__class__.__name__}({self.__str__()})" |
| 97 | |
| 98 | def __str__(self) -> str: |
| 99 | if self.__message: |
| 100 | msg = f"{self.__message}: {self.status}" |
| 101 | else: |
| 102 | msg = f"{self.status}" |
| 103 | |
| 104 | if self.data is not None: |
no outgoing calls
no test coverage detected
searching dependent graphs…