-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_error.py
47 lines (34 loc) · 1.04 KB
/
custom_error.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Custom Error in python
"""
import requests
class Network:
"""`Netword` Class
"""
class NetworkProblem(Exception):
"""Define custom exception
subclass `Exception`
"""
def communicate(self, url: str) -> requests.Response:
"""communicate to url
Args:
url (str): page url
Raises:
self.NetworkProblem: unable to establish connection
Returns:
requests.Response: page respones(request.get)
"""
try:
respones = requests.get(url)
except requests.exceptions.ConnectionError:
raise self.NetworkProblem(
"unable to establish connection") from None
return respones
if __name__ == "__main__":
network = Network()
# network.communicate('https://github.com/dori-dev')
try:
r = network.communicate('https://github.com/dori-dev')
except network.NetworkProblem:
print("exception raised, no connection to internet!")
else:
print(r.status_code)