Format the response of transaction request in a nicer way

This commit is contained in:
Erik Johnston 2015-02-17 13:58:52 +00:00
parent c82e26ad4b
commit 659ead082f
2 changed files with 35 additions and 6 deletions

View File

@ -118,7 +118,7 @@ class FederationServer(FederationBase):
def handle_failure(failure): def handle_failure(failure):
failure.trap(FederationError) failure.trap(FederationError)
self.enqueue_failure(failure.value, transaction.origin) self.send_failure(failure.value, transaction.origin)
d.addErrback(handle_failure) d.addErrback(handle_failure)
@ -132,7 +132,7 @@ class FederationServer(FederationBase):
edu.content edu.content
) )
for failure in getattr(transaction, "failures", []): for failure in getattr(transaction, "pdu_failures", []):
logger.info("Got failure %r", failure) logger.info("Got failure %r", failure)
results = yield defer.DeferredList(dl, consumeErrors=True) results = yield defer.DeferredList(dl, consumeErrors=True)
@ -143,11 +143,15 @@ class FederationServer(FederationBase):
ret.append({}) ret.append({})
else: else:
logger.exception(r[1]) logger.exception(r[1])
ret.append({"error": str(r[1])}) ret.append({"error": str(r[1].value)})
logger.debug("Returning: %s", str(ret)) logger.debug("Returning: %s", str(ret))
response = ret response = {
"pdus": dict(zip(
(p.event_id for p in pdu_list), ret
)),
}
yield self.transaction_actions.set_response( yield self.transaction_actions.set_response(
transaction, transaction,
@ -358,6 +362,13 @@ class FederationServer(FederationBase):
affected=pdu.event_id, affected=pdu.event_id,
) )
raise FederationError(
"ERROR",
403,
"Forbidden",
affected=pdu.event_id,
)
state = None state = None
auth_chain = [] auth_chain = []

View File

@ -91,7 +91,7 @@ class TransactionQueue(object):
if not deferred.called: if not deferred.called:
deferred.errback(failure) deferred.errback(failure)
else: else:
logger.warn("Failed to send pdu", failure) logger.warn("Failed to send pdu", failure.value)
with PreserveLoggingContext(): with PreserveLoggingContext():
self._attempt_new_transaction(destination).addErrback(eb) self._attempt_new_transaction(destination).addErrback(eb)
@ -116,7 +116,7 @@ class TransactionQueue(object):
if not deferred.called: if not deferred.called:
deferred.errback(failure) deferred.errback(failure)
else: else:
logger.warn("Failed to send edu", failure) logger.warn("Failed to send edu", failure.value)
with PreserveLoggingContext(): with PreserveLoggingContext():
self._attempt_new_transaction(destination).addErrback(eb) self._attempt_new_transaction(destination).addErrback(eb)
@ -133,6 +133,15 @@ class TransactionQueue(object):
(failure, deferred) (failure, deferred)
) )
def eb(failure):
if not deferred.called:
deferred.errback(failure)
else:
logger.warn("Failed to send failure", failure.value)
with PreserveLoggingContext():
self._attempt_new_transaction(destination).addErrback(eb)
yield deferred yield deferred
@defer.inlineCallbacks @defer.inlineCallbacks
@ -249,6 +258,15 @@ class TransactionQueue(object):
transaction, json_data_cb transaction, json_data_cb
) )
code = 200 code = 200
if response:
for e_id, r in getattr(response, "pdus", {}).items():
if "error" in r:
logger.warn(
"Transaction returned error for %s: %s",
e_id, r,
)
except HttpResponseException as e: except HttpResponseException as e:
code = e.code code = e.code
response = e.response response = e.response