forked from rDrama/rDrama
handle error
parent
47f099bf36
commit
f97552b076
|
@ -7,6 +7,7 @@ from collections import Counter
|
||||||
import gevent
|
import gevent
|
||||||
import qrcode
|
import qrcode
|
||||||
from sqlalchemy.orm import aliased, load_only
|
from sqlalchemy.orm import aliased, load_only
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
from files.classes import *
|
from files.classes import *
|
||||||
from files.classes.leaderboard import Leaderboard
|
from files.classes.leaderboard import Leaderboard
|
||||||
|
@ -33,8 +34,14 @@ def _add_profile_view(vid, uid):
|
||||||
if view: view.last_view_utc = int(time.time())
|
if view: view.last_view_utc = int(time.time())
|
||||||
else: view = ViewerRelationship(viewer_id=vid, user_id=uid)
|
else: view = ViewerRelationship(viewer_id=vid, user_id=uid)
|
||||||
db.add(view)
|
db.add(view)
|
||||||
|
|
||||||
|
try:
|
||||||
|
db.commit()
|
||||||
|
except IntegrityError as e:
|
||||||
|
db.rollback()
|
||||||
|
if not str(e).startswith('(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "'):
|
||||||
|
print(STARS + e + STARS, flush=True)
|
||||||
|
|
||||||
db.commit()
|
|
||||||
db.close()
|
db.close()
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue