From 485edb67ef4fb940ab060a17022b63e5304bf6b4 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 19 Dec 2016 16:46:29 +0100 Subject: [PATCH] Some error catching --- rowers/views.py | 57 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/rowers/views.py b/rowers/views.py index 5f1f1cc7..25b704f1 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -830,26 +830,42 @@ def list_c2_upload_view(request,id=0): @login_required() def workout_tcxemail_view(request,id=0): message = "" + successmessage = "" r = Rower.objects.get(user=request.user) w = Workout.objects.get(id=id) if (checkworkoutuser(request.user,w)): - tcxfile = stravastuff.createstravaworkoutdata(w) - if settings.DEBUG: - res = handle_sendemailtcx.delay(r.user.first_name, - r.user.last_name, - r.user.email,tcxfile) + try: + tcxfile = stravastuff.createstravaworkoutdata(w) + if settings.DEBUG: + res = handle_sendemailtcx.delay(r.user.first_name, + r.user.last_name, + r.user.email,tcxfile) - else: - res = queuehigh.enqueue(handle_sendemailtcx,r.user.first_name, - r.user.last_name, - r.user.email,tcxfile) + else: + res = queuehigh.enqueue(handle_sendemailtcx,r.user.first_name, + r.user.last_name, + r.user.email,tcxfile) - successmessage = "The TCX file was sent to you per email" - url = reverse(workout_export_view, - kwargs = { - 'id':str(w.id), - 'successmessage':successmessage, + successmessage = "The TCX file was sent to you per email" + url = reverse(workout_export_view, + kwargs = { + 'id':str(w.id), + 'successmessage':successmessage, }) + except: + successmessage = "" + message = "Something went wrong (strava export) "+str(sys.exc_info()[0]) + with open("media/c2errors.log","a") as errorlog: + errorstring = str(sys.exc_info()[0]) + timestr = strftime("%Y%m%d-%H%M%S") + errorlog.write(timestr+errorstring+"\r\n") + + url = reverse(workout_export_view, + kwargs = { + 'id':str(w.id), + 'message':message, + }) + response = HttpResponseRedirect(url) else: @@ -978,7 +994,9 @@ def workout_c2_upload_view(request,id=0): except: message = "Unexpected Error: "+str(sys.exc_info()[0]) with open("media/c2errors.log","a") as errorlog: - errorlog.write("Unexpected Error: "+str(sys.exc_info()[0])) + errorstring = str(sys.exc_info()[0]) + timestr = time.strftime("%Y%m%d-%H%M%S") + errorlog.write(timestr+errorstring+"\n") # check for duplicate error first if (response.status_code == 409 ): @@ -996,13 +1014,18 @@ def workout_c2_upload_view(request,id=0): except: message = "Something went wrong in workout_c2_upload_view. Response code 200/201 but C2 sync failed: "+response.text with open("media/c2errors.log","a") as errorlog: - errorlog.write("Unexpected Error: "+str(sys.exc_info()[0])) + errorstring = str(sys.exc_info()[0]) + timestr = time.strftime("%Y%m%d-%H%M%S") + errorlog.write(timestr+errorstring+"\n") + else: s = response message = "Something went wrong in workout_c2_upload_view. C2 sync failed." with open("media/c2errors.log","a") as errorlog: - errorlog.write("Unexpected Error: "+response.text()) + errorstring = str(sys.exc_info()[0]) + timestr = time.strftime("%Y%m%d-%H%M%S") + errorlog.write(timestr+errorstring+"\n") else: message = "You are not authorized to upload this workout"