Skip to content
Snippets Groups Projects
Verified Commit 94a9fb35 authored by Jonas Leder's avatar Jonas Leder
Browse files

fix abusing exceptions to check if row exists in db

parent 14b9eb64
Loading
Checking pipeline status
......@@ -21,11 +21,11 @@ def redirect_shorten_url(request, short_url):
abort(500)
if not error_404: #If there was no 404 error before, redirect the user. If not throw a 404 error
res = cursor.execute('SELECT CALLS FROM ANALYTICS WHERE SHORT_URL=?', [host + "/" + short_url.lower()])
try:
calls = res.fetchone()[0] + 1
row = row = cursor.fetchone()
if not row is None:
calls = row[0] + 1
cursor.execute('UPDATE ANALYTICS SET CALLS = ? WHERE SHORT_URL=?', (str(calls), host + "/" + short_url.lower()))
except:
print(Exception)
else:
cursor.execute('INSERT INTO ANALYTICS (SHORT_URL) VALUES ("' + host + "/" + short_url.lower() + "\")")
return redirect(url) #I use temp redirect here, because the owner of a link can delete it. If then the link is reused, the user will maybe redirected to the wrong page
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment