How do I handle exceptions on Python Social Auth [closed]

非 Y 不嫁゛ 提交于 2019-11-30 02:59:17

问题


How do I handle this kind of exception AuthAlreadyAssociated on Python Social Auth?

All the answers I found are for Django Social Auth but it seems plenty has changed ever since they were written.


回答1:


You can create a new middleware in your app's middleware.py:

from social_django.middleware import SocialAuthExceptionMiddleware
from social_core import exceptions as social_exceptions     
from django.http import HttpResponse

class MySocialAuthExceptionMiddleware(SocialAuthExceptionMiddleware):
    def process_exception(self, request, exception):
        if hasattr(social_exceptions, exception.__class__.__name__):
            # Here you can handle the exception as you wish
            return HttpResponse("Exception %s while processing your social account." % exception)
        else:
            return super(MySocialAuthExceptionMiddleware, self).process_exception(request, exception)

and add its path to settings.py

MIDDLEWARE_CLASSES = (
    ...
    'path.to.MySocialAuthExceptionMiddleware',
   )


来源:https://stackoverflow.com/questions/19305986/how-do-i-handle-exceptions-on-python-social-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!