-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
43 lines (34 loc) · 1.44 KB
/
Copy pathexceptions.py
File metadata and controls
43 lines (34 loc) · 1.44 KB
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
import sys
from colorama import Fore
from httpx import ConnectError, ProxyError
class EmptyInputError(Exception):
"""Query string can not be empty."""
class SpecialCharInputError(Exception):
"""Query string must escape special characters"""
class NoImagesFoundError(Exception):
"""Response got no images"""
def error_handler_decorator(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except EmptyInputError:
print(Fore.LIGHTRED_EX + '[ERROR]', Fore.RED + 'Input value can not be empty.')
sys.exit(1)
except SpecialCharInputError:
print(Fore.LIGHTRED_EX + '[ERROR]', Fore.RED + 'Input can not contain special characters.')
sys.exit(1)
except ConnectError:
print(Fore.LIGHTRED_EX + '[CONNECTION ERROR]',
Fore.RED + 'Failed to connect to server. Check your internet connection and try again.')
sys.exit(1)
except ProxyError:
print(Fore.LIGHTRED_EX + '[PROXIES ERROR]',
Fore.RED + 'Failed to connect to server. Check your proxies and try again.')
sys.exit(1)
except TimeoutError:
print(Fore.LIGHTRED_EX + '[ERROR]',
Fore.RED + 'Connection timed out.')
except NoImagesFoundError:
print(Fore.LIGHTRED_EX + '[ERROR]', Fore.RED + 'No images found.')
sys.exit(1)
return wrapper