@@ -22,7 +22,7 @@ def build_request(
22
22
if len (category ) > 0 :
23
23
for c in category :
24
24
if not c .lower () in ["programming" , "miscellaneous" , "dark" ]:
25
- raise Exception (
25
+ raise ValueError (
26
26
'''Invalid category selected. Available categories are:
27
27
"programming"
28
28
"miscellaneous"
@@ -43,7 +43,7 @@ def build_request(
43
43
"racist" ,
44
44
"sexist"
45
45
]:
46
- raise Exception (
46
+ raise ValueError (
47
47
'''\n \n
48
48
You have blacklisted flags which are not available.
49
49
Available flags are:
@@ -59,13 +59,13 @@ def build_request(
59
59
else :
60
60
blacklistFlags = None
61
61
62
- if response_format not in ["json" , "xml" , "yaml" ]:
62
+ if response_format not in ["json" , "xml" , "yaml" , "txt" ]:
63
63
raise Exception (
64
64
"Response format must be either json, xml or yaml."
65
65
)
66
66
if type :
67
67
if type not in ["single" , "twopart" ]:
68
- raise Exception (
68
+ raise ValueError (
69
69
'''Invalid joke type.
70
70
Available options are "single" or "twopart".'''
71
71
)
@@ -75,7 +75,7 @@ def build_request(
75
75
76
76
if search_string :
77
77
if not isinstance (search_string , str ):
78
- raise Exception ("search_string must be a string." )
78
+ raise ValueError ("search_string must be a string." )
79
79
return
80
80
else :
81
81
search_string = urllib .parse .quote (search_string )
@@ -89,13 +89,13 @@ def build_request(
89
89
range_limit = dict ["jokes" ]["totalCount" ]
90
90
91
91
if len (id_range ) > 2 :
92
- raise Exception ("id_range must be no longer than 2 items." )
92
+ raise ValueError ("id_range must be no longer than 2 items." )
93
93
elif id_range [0 ] < 0 :
94
- raise Exception (
94
+ raise ValueError (
95
95
"id_range[0] must be greater than or equal to 0."
96
96
)
97
97
elif id_range [1 ] > range_limit :
98
- raise Exception (
98
+ raise ValueError (
99
99
f"id_range[1] must be less than or equal to { range_limit - 1 } ."
100
100
)
101
101
0 commit comments