def catch_errors(f):
    """
    Catches specific errors in admin actions and shows a friendly error.
    """

    @functools.wraps(f)
    def wrapper(self, request, *args, **kwargs):
        try:
            return f(self, request, *args, **kwargs)
        except exceptions.CertificateExpired:
            self.message_user(
                request,
                _('The AFIP Taxpayer certificate has expired.'),
                messages.ERROR,
            )
        except exceptions.UntrustedCertificate:
            self.message_user(
                request,
                _('The AFIP Taxpayer certificate is untrusted.'),
                messages.ERROR,
            )
        except exceptions.CorruptCertificate:
            self.message_user(
                request,
                _('The AFIP Taxpayer certificate is corrupt.'),
                messages.ERROR,
            )
        except exceptions.AuthenticationError as e:
            logger.exception('AFIP auth failed')
            self.message_user(
                request,
                _('An unknown authentication error has ocurred: %s') % e,
                messages.ERROR,
            )

    return wrapper
def catch_errors ( f ) : @ functools . wraps ( f ) def wrapper ( self , request , * args , ** kwargs ) : try : return f ( self , request , * args , ** kwargs ) except exceptions . CertificateExpired : self . message_user ( request , _ ( 'The AFIP Taxpayer certificate has expired.' ) , messages . ERROR , ) except exceptions . UntrustedCertificate : self . message_user ( request , _ ( 'The AFIP Taxpayer certificate is untrusted.' ) , messages . ERROR , ) except exceptions . CorruptCertificate : self . message_user ( request , _ ( 'The AFIP Taxpayer certificate is corrupt.' ) , messages . ERROR , ) except exceptions . AuthenticationError as e : logger . exception ( 'AFIP auth failed' ) self . message_user ( request , _ ( 'An unknown authentication error has ocurred: %s' ) % e , messages . ERROR , ) return wrapper
Catches specific errors in admin actions and shows a friendly error.