Skip to content

Commit

Permalink
fix: better error handling related of content exception
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreSilveiraAzion committed Aug 8, 2024
1 parent 8191448 commit 067d607
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion edgesql-shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def default(self, line):
utils.write_output(f"{output['error']}")
return
except RuntimeError as er:
utils.write_output(f"Error executing SQL command: {er}")
utils.write_output(f"{er}")
return
if output.get('data'):
self.query_output(output['data']['rows'], output['data']['columns'])
Expand Down
9 changes: 8 additions & 1 deletion edgesql.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,17 @@ def execute(self, buffer):

try:
response = requests.post(url, json=data, headers=self.__headers(), timeout=self.timeout)

# Check if the response content is empty
if not response.content:
result['error'] = f"Empty response from server. statusCode={response.status_code}"
return result

try:
json_data = response.json()
except json.JSONDecodeError as e:
raise ValueError(f"Error decoding JSON response: {e}. statusCode={response.status_code}") from e
result['error'] = f"Error decoding JSON response: {e}. statusCode={response.status_code}"
return result

if response.status_code == HTTPStatus.OK:
result_data = json_data.get('data', [])
Expand Down

0 comments on commit 067d607

Please sign in to comment.