File tree Expand file tree Collapse file tree 1 file changed +5
-9
lines changed
Expand file tree Collapse file tree 1 file changed +5
-9
lines changed Original file line number Diff line number Diff line change @@ -65,20 +65,16 @@ def get_single_opportunity(opportunity_id: int):
6565def get_opportunity_via_json ():
6666 """GET /opportunity expects a JSON payload with {"id": <int>}."""
6767 data = request .get_json ()
68- if not data :
69- abort (400 )
70-
71- if "id" not in data :
72- abort (400 )
68+ opp_id_raw = data .get ("id" ) if data else None
7369
7470 try :
75- opp_id = int (data [ "id" ] )
76- except ValueError :
77- abort (400 )
71+ opp_id = int (opp_id_raw )
72+ except ( ValueError , TypeError ) :
73+ abort (400 , description = "Invalid or missing 'id' in JSON payload." )
7874
7975 opp = db .session .get (Opportunities , opp_id )
8076 if not opp :
81- abort (404 )
77+ abort (404 , description = "Opportunity not found." )
8278
8379 return opportunity_to_dict (opp )
8480
You can’t perform that action at this time.
0 commit comments