unified all notokenerrors
This commit is contained in:
@@ -40,7 +40,7 @@ from rowers.models import Rower,Workout
|
||||
from rowers.models import checkworkoutuser
|
||||
import dataprep
|
||||
from dataprep import columndict
|
||||
from utils import uniqify,isprorower,myqueue
|
||||
from utils import uniqify,isprorower,myqueue,NoTokenError, custom_exception_handler
|
||||
from uuid import uuid4
|
||||
import stravalib
|
||||
from stravalib.exc import ActivityUploadFailed,TimeoutExceeded
|
||||
@@ -63,32 +63,6 @@ except ImportError:
|
||||
from utils import geo_distance,ewmovingaverage
|
||||
|
||||
|
||||
# Custom exception handler, returns a 401 HTTP message
|
||||
# with exception details in the json data
|
||||
def custom_exception_handler(exc,message):
|
||||
|
||||
response = {
|
||||
"errors": [
|
||||
{
|
||||
"code": str(exc),
|
||||
"detail": message,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
res = HttpResponse(message)
|
||||
res.status_code = 401
|
||||
res.json = json.dumps(response)
|
||||
|
||||
return res
|
||||
|
||||
# Custom error class - to raise a NoTokenError
|
||||
class StravaNoTokenError(Exception):
|
||||
def __init__(self,value):
|
||||
self.value=value
|
||||
|
||||
def __str__(self):
|
||||
return repr(self.value)
|
||||
|
||||
|
||||
# Exchange access code for long-lived access token
|
||||
@@ -462,7 +436,7 @@ def workout_strava_upload(user,w):
|
||||
res = -1
|
||||
if (r.stravatoken == '') or (r.stravatoken is None):
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
raise StravaNoTokenError("Your hovercraft is full of eels")
|
||||
raise NoTokenError("Your hovercraft is full of eels")
|
||||
else:
|
||||
if (checkworkoutuser(user,w)):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user