55use Exception ;
66use Grayloon \Magento \Magento ;
77use Illuminate \Support \Facades \Http ;
8+ use Illuminate \Support \Facades \Log ;
89
910abstract class AbstractApi
1011{
@@ -57,7 +58,7 @@ protected function constructRequest()
5758 protected function get ($ path , $ parameters = [])
5859 {
5960 return $ this ->checkExceptions (Http::withToken ($ this ->magento ->token )
60- ->get ($ this ->apiRequest .$ path , $ parameters ));
61+ ->get ($ this ->apiRequest .$ path , $ parameters ), $ this -> apiRequest . $ path , $ parameters );
6162 }
6263
6364 /**
@@ -71,7 +72,7 @@ protected function get($path, $parameters = [])
7172 protected function post ($ path , $ parameters = [])
7273 {
7374 return $ this ->checkExceptions (Http::withToken ($ this ->magento ->token )
74- ->post ($ this ->apiRequest .$ path , $ parameters ));
75+ ->post ($ this ->apiRequest .$ path , $ parameters ), $ this -> apiRequest . $ path , $ parameters );
7576 }
7677
7778 /**
@@ -85,7 +86,7 @@ protected function post($path, $parameters = [])
8586 protected function put ($ path , $ parameters = [])
8687 {
8788 return $ this ->checkExceptions (Http::withToken ($ this ->magento ->token )
88- ->put ($ this ->apiRequest .$ path , $ parameters ));
89+ ->put ($ this ->apiRequest .$ path , $ parameters ), $ this -> apiRequest . $ path , $ parameters );
8990 }
9091
9192 /**
@@ -99,7 +100,7 @@ protected function put($path, $parameters = [])
99100 protected function delete ($ path , $ parameters = [])
100101 {
101102 return $ this ->checkExceptions (Http::withToken ($ this ->magento ->token )
102- ->delete ($ this ->apiRequest .$ path , $ parameters ));
103+ ->delete ($ this ->apiRequest .$ path , $ parameters ), $ this -> apiRequest . $ path , $ parameters );
103104 }
104105
105106 /**
@@ -109,12 +110,18 @@ protected function delete($path, $parameters = [])
109110 * @return void
110111 * @throws \Exception
111112 */
112- protected function checkExceptions ($ response )
113+ protected function checkExceptions ($ response, $ endpoint , $ parameters )
113114 {
114115 if ($ response ->serverError ()) {
115116 throw new Exception ($ response ['message ' ] ?? $ response );
116117 }
117118
119+ if (! $ response ->successful ()) {
120+ if (config ('magento.log_failed_requests ' )) {
121+ Log::info ('[MAGENTO API][STATUS] ' .$ response ->status ().' [ENDPOINT] ' .$ endpoint .' [PARAMETERS] ' .json_encode ($ parameters ).' [RESPONSE] ' .json_encode ($ response ->json ()));
122+ }
123+ }
124+
118125 return $ response ;
119126 }
120127
0 commit comments