Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,23 @@ async def get_url(alias: str):
alias_queue.put(alias)
return RedirectResponse(url_output)


@app.post("/delete/{alias}")
async def delete_url(alias: str):
logging.debug(f"/delete called with alias: {alias}")
with MetricsHandler.query_time.labels("delete").time():
if sqlite_helpers.delete_url(DATABASE_FILE, alias):
qr_code_cache.delete(alias)
cache.delete(alias)
return {"message": "URL deleted successfully"}
else:
try:
with MetricsHandler.query_time.labels("delete").time():
if sqlite_helpers.delete_url(DATABASE_FILE, alias):
try: # URL deleted, now attempt the associated data
qr_code_cache.delete(alias)
cache.delete(alias)
except Exception:
logging.exception(f"Error deleting alias {alias} from cache") # log failure without raising exception
Comment on lines +140 to +144
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do the nested try for now, and watch the logs to see what happens


return {"message": "URL deleted successfully"}
raise HTTPException(status_code=HttpResponse.NOT_FOUND.code)
except Exception:
logging.error(f"Unexpected error in delete_url for {alias}")
raise HTTPException(status_code=HttpResponse.INTERNAL_SERVER_ERROR.code)

@app.get("/qr/{alias}")
async def qr(alias: str):
Expand Down