diff --git a/src/Helpers/Saloon/RecordsRequestAndResponses.php b/src/Helpers/Saloon/RecordsRequestAndResponses.php index c636844..5f6520d 100644 --- a/src/Helpers/Saloon/RecordsRequestAndResponses.php +++ b/src/Helpers/Saloon/RecordsRequestAndResponses.php @@ -3,36 +3,35 @@ namespace Flavorly\LaravelHelpers\Helpers\Saloon; use GuzzleHttp\TransferStats; -use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseInterface; -use Saloon\Http\PendingRequest; +use Saloon\Config; use Saloon\Http\Response; +use Saloon\Http\PendingRequest; -trait RecordsRequestAndResponses +class RecordsRequestAndResponses { /** * Little debug help to see the request and response pairs to Ray * - * Usage: call this method in your Connector __construct, so it's only registered once + * Usage: call this method in your AppServiceProvider */ - public function debugRequestsAndResponses(): void + public static function saloonDebugging(): void { if (app()->hasDebugModeEnabled() && config('laravel-helpers.debug-requests', true)) { - $this->debugRequest(function (PendingRequest $pendingRequest, RequestInterface $psrRequest) { + Config::globalMiddleware()->onRequest(function (PendingRequest $pendingRequest) { ray('Dispatching Request', $pendingRequest); + + $pendingRequest->config()->set([ + 'on_stats' => function (TransferStats $stats) { + // @codeCoverageIgnoreStart + ray('[Guzzle Response Body]', (string) $stats->getResponse()?->getBody()); + // @codeCoverageIgnoreEnd + }, + ]); }); - $this->debugResponse(function (Response $response, ResponseInterface $psrResponse) { + Config::globalMiddleware()->onResponse(function (Response $response) { ray('Response Received', $response); }); - - $this->config()->set([ - 'on_stats' => function (TransferStats $stats) { - // @codeCoverageIgnoreStart - ray('[Guzzle Response Body]', (string) $stats->getResponse()?->getBody()); - // @codeCoverageIgnoreEnd - }, - ]); } } }