Пример #1
0
def _switchState(transition_schema, old_state, new_state):
    if new_state in transition_schema[old_state]:
        return
    else:
        raise error.InternalServerError(
            'Transition from state %s to %s not allowed' %
            (old_state, new_state))
Пример #2
0
    def _handleErrorReply(self, err, header):

        if err.check(WebError) is None:
            if err.check(ConnectionRefusedError):
                # could not contact NSA
                msg = 'Could not contact NSA %s. Reason: %s' % (header.provider_nsa, err.getErrorMessage())
                ex = error.DownstreamNSAError(msg, nsa_id=header.provider_nsa)
                return failure.Failure(ex)
            else:
                # cannot handle it here
                return err

        if err.value.status != b'500':
            log.msg("Got error with non-500 status. Message: %s" % err.getErrorMessage(), system=LOG_SYSTEM)
            return err

        fault_code, fault_string, detail = minisoap.parseFault(err.value.response)

        service_exception = None
        if detail:
            service_exception = nsiconnection.parse(detail)

        if service_exception is None:
            # this is not entirely correct, but it isn't really wrong either
            ex = error.InternalServerError(fault_string)
        else:
            ex = helper.createException(service_exception, header.provider_nsa)

        err = failure.Failure(ex)

        return err
Пример #3
0
def createException(service_exception, provider_nsa):
    # nsiconnection.ServiceException (binding) -> error.NSIError

    try:
        exception_type = error.lookup(service_exception.errorId)
        variables = [
            (tvp.type, tvp.value) for tvp in service_exception.variables
        ] if service_exception.variables else None
        ex = exception_type(service_exception.text, service_exception.nsaId
                            or provider_nsa, service_exception.connectionId,
                            variables)
    except AssertionError as e:
        log.msg('Error looking up error id: %s. Message: %s' %
                (service_exception.errorId, str(e)),
                system=LOG_SYSTEM)
        ex = error.InternalServerError(service_exception.text)

    return ex