File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,12 @@ public function __construct($response)
24
24
}
25
25
26
26
if (!empty ($ this ->errors )) {
27
- $ this ->message = $ this ->errors [0 ]->title ;
27
+ $ message = $ this ->errors [0 ]->detail ;
28
+ if (empty ($ message )) {
29
+ $ message = $ this ->errors [0 ]->title ;
30
+ }
31
+
32
+ $ this ->message = $ message ;
28
33
}
29
34
30
35
$ this ->response = $ response ;
Original file line number Diff line number Diff line change @@ -257,7 +257,7 @@ public function wraps_client_exceptions_as_ukfast_exceptions()
257
257
$ client ->request ('GET ' , '/ ' );
258
258
} catch (ApiException $ e ) {
259
259
$ this ->assertEquals (1 , count ($ e ->getErrors ()));
260
- $ this ->assertEquals ('Testing errors ' , $ e ->getMessage ());
260
+ $ this ->assertEquals ('Testing errors detail ' , $ e ->getMessage ());
261
261
return ;
262
262
}
263
263
@@ -293,6 +293,33 @@ public function wraps_server_exceptions_as_ukfast_exceptions()
293
293
$ this ->expectException (ApiException::class);
294
294
}
295
295
296
+ /**
297
+ * @test
298
+ */
299
+ public function defaults_exception_message_to_title_if_no_detail_is_set ()
300
+ {
301
+ $ mock = new MockHandler ([
302
+ new Response (500 , [], json_encode ([
303
+ 'errors ' => [[
304
+ 'title ' => 'Testing errors title ' ,
305
+ 'status ' => 500 ,
306
+ ]]
307
+ ])),
308
+ ]);
309
+ $ handler = HandlerStack::create ($ mock );
310
+ $ guzzle = new Guzzle (['handler ' => $ handler ]);
311
+ $ client = new Client ($ guzzle );
312
+
313
+ try {
314
+ $ client ->request ('GET ' , '/ ' );
315
+ } catch (ApiException $ e ) {
316
+ $ this ->assertEquals ('Testing errors title ' , $ e ->getMessage ());
317
+ return ;
318
+ }
319
+
320
+ $ this ->expectException (ApiException::class);
321
+ }
322
+
296
323
/**
297
324
* @test
298
325
*/
You can’t perform that action at this time.
0 commit comments