Skip to content

Commit fc105d9

Browse files
committed
Improved 404 and error handling
1 parent 52b2f96 commit fc105d9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

apps/dot_ext/views/authorization.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,16 @@ def post(self, request, *args, **kwargs):
367367
return json_response_from_oauth2_error(error)
368368

369369
try:
370-
body = json.loads(request.body.decode("UTF-8"))
371-
token = at_model.objects.get(token=body.get("token"))
370+
tkn = json.loads(request.body.decode("UTF-8")).get("token")
372371
except Exception:
373-
token = at_model.objects.get(
374-
token=request.POST.get("token"))
372+
tkn = request.POST.get("token")
375373

376-
if token is None:
377-
return HttpResponse("Token was Not Found. Please check the value and try again.",
374+
try:
375+
token = at_model.objects.get(token=tkn)
376+
except at_model.DoesNotExist:
377+
return HttpResponse(f"Token {tkn} was Not Found. Please check the value and try again.",
378378
status=status.HTTP_404_NOT_FOUND)
379+
379380
try:
380381
dag = DataAccessGrant.objects.get(
381382
beneficiary=token.user,

0 commit comments

Comments
 (0)