5
5
use Exception ;
6
6
use Grayloon \Magento \Magento ;
7
7
use Illuminate \Support \Facades \Http ;
8
+ use Illuminate \Support \Facades \Log ;
8
9
9
10
abstract class AbstractApi
10
11
{
@@ -57,7 +58,7 @@ protected function constructRequest()
57
58
protected function get ($ path , $ parameters = [])
58
59
{
59
60
return $ this ->checkExceptions (Http::withToken ($ this ->magento ->token )
60
- ->get ($ this ->apiRequest .$ path , $ parameters ));
61
+ ->get ($ this ->apiRequest .$ path , $ parameters ), $ this -> apiRequest . $ path , $ parameters );
61
62
}
62
63
63
64
/**
@@ -71,7 +72,7 @@ protected function get($path, $parameters = [])
71
72
protected function post ($ path , $ parameters = [])
72
73
{
73
74
return $ this ->checkExceptions (Http::withToken ($ this ->magento ->token )
74
- ->post ($ this ->apiRequest .$ path , $ parameters ));
75
+ ->post ($ this ->apiRequest .$ path , $ parameters ), $ this -> apiRequest . $ path , $ parameters );
75
76
}
76
77
77
78
/**
@@ -85,7 +86,7 @@ protected function post($path, $parameters = [])
85
86
protected function put ($ path , $ parameters = [])
86
87
{
87
88
return $ this ->checkExceptions (Http::withToken ($ this ->magento ->token )
88
- ->put ($ this ->apiRequest .$ path , $ parameters ));
89
+ ->put ($ this ->apiRequest .$ path , $ parameters ), $ this -> apiRequest . $ path , $ parameters );
89
90
}
90
91
91
92
/**
@@ -99,7 +100,7 @@ protected function put($path, $parameters = [])
99
100
protected function delete ($ path , $ parameters = [])
100
101
{
101
102
return $ this ->checkExceptions (Http::withToken ($ this ->magento ->token )
102
- ->delete ($ this ->apiRequest .$ path , $ parameters ));
103
+ ->delete ($ this ->apiRequest .$ path , $ parameters ), $ this -> apiRequest . $ path , $ parameters );
103
104
}
104
105
105
106
/**
@@ -109,12 +110,18 @@ protected function delete($path, $parameters = [])
109
110
* @return void
110
111
* @throws \Exception
111
112
*/
112
- protected function checkExceptions ($ response )
113
+ protected function checkExceptions ($ response, $ endpoint , $ parameters )
113
114
{
114
115
if ($ response ->serverError ()) {
115
116
throw new Exception ($ response ['message ' ] ?? $ response );
116
117
}
117
118
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
+
118
125
return $ response ;
119
126
}
120
127
0 commit comments