Log error responses

This commit is contained in:
Jeremy Dormitzer 2019-04-13 16:54:05 -04:00
parent 45b441130a
commit dfdf9dd6d0

View File

@ -9,7 +9,6 @@ use ActivityPub\Objects\ObjectsService;
use ActivityPub\Utils\DateTimeProvider; use ActivityPub\Utils\DateTimeProvider;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Promise\Promise; use GuzzleHttp\Promise\Promise;
use function GuzzleHttp\Promise\settle;
use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Request;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -119,14 +118,22 @@ class DeliveryHandler implements EventSubscriberInterface
$request = $request->withHeader( 'Signature', $signature ); $request = $request->withHeader( 'Signature', $signature );
} else { } else {
$this->logger->warning( $this->logger->warning(
'Unable to find a keypair for actor {id}; delivering without signature', 'Unable to find a keypair for actor; delivering without signature',
array( 'id' => $actor['id'] ) array( 'actorId' => $actor['id'] )
); );
} }
$requestPromises[$inbox] = $this->httpClient->sendAsync( $request, array( 'timeout' => 3 ) ); $requestPromises[$inbox] = $this->httpClient->sendAsync( $request, array( 'timeout' => 3 ) );
} }
$responses = settle( $requestPromises )->wait(); $responses = \GuzzleHttp\Promise\settle( $requestPromises )->wait();
// TODO handle responses by logging any errors foreach ( $responses as $inbox => $response ) {
if ( $response['state'] === 'rejected' ) {
$e = $response['reason'];
$this->logger->error(
'Error delivering activity',
array( 'inboxUri' => $inbox, 'errorMessage' => $e->getMessage() )
);
}
}
} }
/** /**