@@ -59,6 +59,11 @@ class ApiClient implements ApiClientInterface
5959 */
6060 private $ endpoint ;
6161
62+ /**
63+ * @var bool
64+ */
65+ private $ logNotOk = false ;
66+
6267 /**
6368 * @var PayloadSerializer
6469 */
@@ -97,12 +102,38 @@ public function __construct(
97102 $ this ->eventDispatcher = $ eventDispatcher ?: new EventDispatcher ();
98103 }
99104
105+ /**
106+ * Set logging of error explanations when response is not ok.
107+ *
108+ * @param bool $logNotOk
109+ *
110+ * @return ApiClient
111+ */
112+ public function setLogNotOk ($ logNotOk )
113+ {
114+ $ this ->logNotOk = $ logNotOk ;
115+
116+ return $ this ;
117+ }
118+
119+ /**
120+ * Get the boolean of logging of error explanations when response is not ok.
121+ *
122+ * @param string $endpoint
123+ *
124+ * @return string
125+ */
126+ public function isLogNotOk ()
127+ {
128+ return $ this ->logNotOk ;
129+ }
130+
100131 /**
101132 * Get the endpoint for this payload.
102133 *
103134 * @param string $endpoint
104135 *
105- * @return void
136+ * @return string
106137 */
107138 public function getEndpoint ()
108139 {
@@ -114,7 +145,7 @@ public function getEndpoint()
114145 *
115146 * @param string $endpoint
116147 *
117- * @return void
148+ * @return ApiClient
118149 */
119150 public function setEndpoint ($ endpoint )
120151 {
@@ -126,7 +157,7 @@ public function setEndpoint($endpoint)
126157 /**
127158 * Reset the endpoint for this payload.
128159 *
129- * @return void
160+ * @return ApiClient
130161 */
131162 public function resetEndpoint ()
132163 {
@@ -220,6 +251,10 @@ private function doSend($method, array $data, $token = null)
220251
221252 $ this ->eventDispatcher ->dispatch (self ::EVENT_RESPONSE , new ResponseEvent ($ responseData ));
222253
254+ if ($ this ->isLogNotOk () && !$ responseData ->isOk ()) {
255+ error_log ($ responseData ->getErrorExplanation ());
256+ }
257+
223258 return $ responseData ;
224259 } catch (\Exception $ e ) {
225260 throw new SlackException ('Failed to process response from the Slack API ' , null , $ e );
0 commit comments