@@ -89,6 +89,7 @@ private function getEndpoint(string $name, array $arguments) : EndpointInterface
8989 $ endpointClass = $ namespace . '\\' . \ucfirst ($ name );
9090 if (!\in_array ($ name , self ::$ validEndpoints , true ) || !class_exists ($ endpointClass )) {
9191 $ message = sprintf ('%s (%s) is not valid TK API endpoint. ' , $ name , $ endpointClass );
92+ $ this ->logger ->error ($ message );
9293 throw new BadMethodCallException ($ message );
9394 }
9495 return $ this ->endpointFactory ($ endpointClass , $ arguments );
@@ -119,8 +120,9 @@ private function request(EndpointInterface $endpoint) : array
119120 $ responseBodyString = (string ) $ response ->getBody ();
120121 $ responseBody = json_decode ($ responseBodyString , true );
121122 if ($ responseBody ['status ' ] === 'FAILURE ' ) {
123+ $ this ->logger ->error ('TK API ERROR ' , $ responseBody ['message ' ]);
122124 throw new RequestException (
123- 'API ERROR: ' .
125+ 'TK API ERROR: ' .
124126 $ responseBody ['message ' ]['code ' ] . ' - ' .
125127 $ responseBody ['message ' ]['description ' ] . ' OriginalResponse: ' . $ responseBodyString
126128 );
@@ -156,11 +158,22 @@ private function httpRequest(EndpointInterface $endpoint) : ResponseInterface
156158 $ uri .= '? ' . http_build_query ($ endpoint ->getQueryParams ());
157159 }
158160 $ options ['headers ' ] = $ this ->headers ;
161+
162+ $ this ->logger ->debug (
163+ 'API call for : ' . $ endpoint ->getEndpoint (),
164+ [
165+ 'httpRequestMethod ' => $ httpRequestMethod ,
166+ 'uri ' => $ uri ,
167+ 'headers ' => $ this ->headers ,
168+ 'queryParams ' => $ endpoint ->getQueryParams ()
169+ ]
170+ );
159171 try {
160172 return $ this ->guzzleClient ->{$ httpRequestMethod }($ uri , $ options );
161173 } catch (GuzzleRequestException $ e ) {
162174 $ exceptionMessage = (string ) $ e ->getResponse ()->getBody ()->getContents ();
163- $ message = sprintf ('TK API Request Error: %s ' , $ exceptionMessage );
175+ $ message = sprintf ('TK API REQUEST ERROR: %s ' , $ exceptionMessage );
176+ $ this ->logger ->error ($ message );
164177 throw new RequestException ($ message );
165178 }
166179 }
0 commit comments