Skip to content

Commit

Permalink
Handle HttpResponses returned by the pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed khan committed Jul 6, 2016
1 parent 7ae6986 commit 2078fa3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rest_social_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
from social.strategies.utils import get_strategy
from social.utils import user_is_authenticated, parse_qs
from social.apps.django_app.views import _do_login as social_auth_login
from django.http import HttpResponse
from social.exceptions import AuthException
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from rest_framework import status
from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import AllowAny
from requests.exceptions import HTTPError

from .serializers import (OAuth2InputSerializer, OAuth1InputSerializer, UserSerializer,
TokenSerializer, UserTokenSerializer, JWTSerializer, UserJWTSerializer)

Expand Down Expand Up @@ -110,6 +110,8 @@ def post(self, request, *args, **kwargs):
user = self.get_object()
except (AuthException, HTTPError) as e:
return self.respond_error(e)
if isinstance(user, HttpResponse): # An error happened and pipeline returned HttpResponse instead of user
return user
resp_data = self.get_serializer(instance=user)
self.do_login(request.backend, user)
return Response(resp_data.data)
Expand Down

0 comments on commit 2078fa3

Please sign in to comment.