Skip to content

Commit

Permalink
Updated OK messages
Browse files Browse the repository at this point in the history
  • Loading branch information
UTXOnly committed Mar 9, 2024
1 parent 561883a commit 92b2419
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docker_stuff/python_stuff/event_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def add_event(self, conn, cur) -> None:
def evt_response(self, results_json, http_status_code):
response = {
"event": "OK",
"subscription_id": "n0stafarian419",
"event_id": "n0stafarian419",
"results_json": results_json,
}
return JSONResponse(content=response, status_code=http_status_code)
Expand Down
5 changes: 3 additions & 2 deletions docker_stuff/python_stuff/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ async def handle_new_event(request: Request) -> JSONResponse:

except psycopg.IntegrityError as e:
conn.rollback()
logger.info(f"Event with ID {event_obj.event_id} already exists")
return event_obj.evt_response(
f"Event with ID {event_obj.event_id} already exists", 409
"true", 409, "duplicate: already have this event"
)
except Exception as e:
conn.rollback()
return event_obj.evt_response(
f"Error:{e} occured adding event {event_obj.event_id}", 409
"false", 500, "error: could not connect to the database"
)


Expand Down
12 changes: 9 additions & 3 deletions docker_stuff/python_stuff/websocket_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __init__(self, response_data):
"""
self.event_type = response_data["event"]
self.subscription_id = response_data["subscription_id"]
self.subscription_id = response_data["event_id"]
try:
self.results = json.loads(response_data["results_json"])
except json.JSONDecodeError as json_error:
Expand All @@ -170,6 +170,12 @@ def __init__(self, response_data):
self.results = ""

self.comment = ""
self.event_response: Tuple[str, Optional[str], str, Optional[str]] = (
self.event_type,
self.subscription_id,
self.results,
response_data["message"]
)
self.rate_limit_response: Tuple[str, Optional[str], str, Optional[str]] = (
"OK",
"nostafarian419",
Expand Down Expand Up @@ -401,8 +407,8 @@ async def send_event_to_handler(
f"Formatted response data from send_event_to_handler function: {formatted_response}"
)
await websocket.send(json.dumps(formatted_response))
elif response.status == 409:
return response_object.duplicate_response
elif response.status != 200:
return response_object.event_response
except Exception as e:
logger.error(f"An error occurred while sending the event to the handler: {e}")

Expand Down

0 comments on commit 92b2419

Please sign in to comment.