Skip to content

Commit

Permalink
Bug Fix: Empty Response for 200 code error handling (by Shahzaib and …
Browse files Browse the repository at this point in the history
…Sanchit)
  • Loading branch information
SanchitMinocha committed Dec 8, 2024
1 parent c18cdd1 commit 9fc2e23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/pywris/surface_water/storage/reservoir.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,15 @@ def get_reservoirs(
reservoir_names_str = ",".join(["'" + reservoir + "'" for reservoir in selected_reservoirs])
reservoir_data = get_reservoir_data(reservoir_names_str, timestep, start_date, end_date)
reservoir_df = pd.json_normalize(reservoir_data)

print(reservoir_df)
# Create dictionary of reservoir objects
reservoirs = {}
print(selected_reservoirs)
for res_name in selected_reservoirs:
print(res_name)
sel_res_df = reservoir_df[reservoir_df['Reservoir Name']==res_name]
sel_res_state = sel_res_df['Parent']
print(sel_res_df['Parent'])
sel_res_state = sel_res_df['Parent'].values()[0]

sel_res = Reservoir(res_name, sel_res_state)
sel_res.district = district_dict[sel_res_df['Child']]
Expand Down
7 changes: 6 additions & 1 deletion src/pywris/utils/fetch_wris.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
import json

def get_response(url,payload, method):

Expand All @@ -11,7 +12,11 @@ def get_response(url,payload, method):

# Checking if the request was successful
if response.status_code == 200:
return response.json()
try:
json_response = response.json()
return json_response
except json.JSONDecodeError:
raise ValueError('Empty Response from the server.')
else:
print("Error:", response.status_code)
raise Exception("Error:", response.status_code)

0 comments on commit 9fc2e23

Please sign in to comment.