File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change 6
6
use FreshMail \ApiV2 \Factory \MonologFactory ;
7
7
use GuzzleHttp \RequestOptions ;
8
8
use Psr \Log \LoggerInterface ;
9
+ use function is_array ;
10
+ use function json_decode ;
9
11
10
12
/**
11
13
* Class to make proper request (with authorization) to FreshMail Rest API V2
@@ -74,10 +76,16 @@ public function doRequest(string $uri, array $params = [])
74
76
throw new UnauthorizedException ('Request unauthorized ' );
75
77
}
76
78
79
+ $ code = 0 ;
80
+ $ res = json_decode ($ exception ->getResponse ()->getBody ()->getContents ());
81
+ if (NULL !== $ res && is_array ($ res ->errors )) {
82
+ $ code = array_pop ($ res ->errors )->code ?? 0 ;
83
+ }
84
+
77
85
throw new \FreshMail \ApiV2 \ClientException (sprintf (
78
86
'Connection error, error message: %s ' ,
79
87
$ exception ->getResponse ()->getBody ()->getContents ()
80
- ));
88
+ ), $ code );
81
89
} catch (\GuzzleHttp \Exception \ConnectException $ exception ) {
82
90
throw new ConnectionException (sprintf ('Connection error, error message: ' .$ exception ->getMessage ()));
83
91
}
You can’t perform that action at this time.
0 commit comments