Skip to content

Commit

Permalink
add error msgs when grew server is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
khansadaoudi committed Nov 12, 2024
1 parent 8d5d8ef commit 4ac8d50
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions app/utils/grew_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io
import time
import zipfile
from bs4 import BeautifulSoup

import requests
from flask import abort
Expand All @@ -27,19 +28,22 @@ def grew_request(fct_name, data={}, files={}):
error_message = ("Grew requests handler> : Uncaught exception, please report {}".format(e))
print(error_message)
abort(500, {"message": error_message})
try:
response = json.loads(response.text)
if response.get("status") == "ERROR":
error_message = response.get("message")
print("GREW-ERROR : {}".format(error_message) )
abort(406, "GREW-ERROR : {}".format(error_message))

elif response.get("status") == "WARNING":
warning_message = response.get("message")
print("Grew-Warning: {}".format(warning_message))

return response
except Exception as e:
parsed_error_msg = BeautifulSoup(response.text, features="lxml").find('p').contents[0]
abort(500, str(parsed_error_msg))

response = json.loads(response.text)
if response.get("status") == "ERROR":
error_message = response.get("message")
print("GREW-ERROR : {}".format(error_message) )
abort(406, "GREW-ERROR : {}".format(error_message))

elif response.get("status") == "WARNING":
warning_message = response.get("message")
print("Grew-Warning: {}".format(warning_message))

return response


class GrewProjectInterface(TypedDict):
name: str
Expand Down

0 comments on commit 4ac8d50

Please sign in to comment.