@@ -22,7 +22,7 @@ def build_request(
2222 if len (category ) > 0 :
2323 for c in category :
2424 if not c .lower () in ["programming" , "miscellaneous" , "dark" ]:
25- raise Exception (
25+ raise ValueError (
2626 '''Invalid category selected. Available categories are:
2727 "programming"
2828 "miscellaneous"
@@ -43,7 +43,7 @@ def build_request(
4343 "racist" ,
4444 "sexist"
4545 ]:
46- raise Exception (
46+ raise ValueError (
4747 '''\n \n
4848 You have blacklisted flags which are not available.
4949 Available flags are:
@@ -59,13 +59,13 @@ def build_request(
5959 else :
6060 blacklistFlags = None
6161
62- if response_format not in ["json" , "xml" , "yaml" ]:
62+ if response_format not in ["json" , "xml" , "yaml" , "txt" ]:
6363 raise Exception (
6464 "Response format must be either json, xml or yaml."
6565 )
6666 if type :
6767 if type not in ["single" , "twopart" ]:
68- raise Exception (
68+ raise ValueError (
6969 '''Invalid joke type.
7070 Available options are "single" or "twopart".'''
7171 )
@@ -75,7 +75,7 @@ def build_request(
7575
7676 if search_string :
7777 if not isinstance (search_string , str ):
78- raise Exception ("search_string must be a string." )
78+ raise ValueError ("search_string must be a string." )
7979 return
8080 else :
8181 search_string = urllib .parse .quote (search_string )
@@ -89,13 +89,13 @@ def build_request(
8989 range_limit = dict ["jokes" ]["totalCount" ]
9090
9191 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." )
9393 elif id_range [0 ] < 0 :
94- raise Exception (
94+ raise ValueError (
9595 "id_range[0] must be greater than or equal to 0."
9696 )
9797 elif id_range [1 ] > range_limit :
98- raise Exception (
98+ raise ValueError (
9999 f"id_range[1] must be less than or equal to { range_limit - 1 } ."
100100 )
101101
0 commit comments