diff --git a/app/redirectShortenURL.py b/app/redirectShortenURL.py index a12d2bf4307a6d959d6ffa325cb86224e2cd3c59..13069842190972e5e8636489d2d34db910341d09 100644 --- a/app/redirectShortenURL.py +++ b/app/redirectShortenURL.py @@ -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