-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
26 lines (19 loc) · 875 Bytes
/
Copy pathexceptions.py
File metadata and controls
26 lines (19 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""This module defines exceptions."""
import click
class ApiKeyNotFoundError(click.UsageError):
"""Exception raised when API KEY for provider is not provided as option and it is not
present in respected environment variable.
"""
class ApiError(Exception):
"""Exception raised for API HTTP response status codes not in [200...300).
The exception value will be the response object returned by :mod:`requests`
which provides access to all its attributes, eg. :attr:`status_code`,
:attr:`reason` and :attr:`text`, etc.
"""
def __str__(self):
"""Return a string from the HTTP response causing the exception.
The string simply lists the repsonse's status code, reason and text
content, separated with commas.
"""
resp = self.args[0]
return f"{resp.status_code}, {resp.reason}, {resp.text}"