File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -129,4 +129,19 @@ public function it_uses_the_class_of_the_exception_when_no_message_exists(): voi
129129 'detail ' => Exception::class,
130130 ]);
131131 }
132+
133+ public function it_should_deal_with_string_exception_codes (): void
134+ {
135+ $ exception = new class ($ message = 'hell no ' ) extends Exception {
136+ protected $ code = 'nope ' ;
137+ };
138+ $ this ->beConstructedWith ($ exception );
139+
140+ $ this ->toArray ()->shouldBe ([
141+ 'status ' => 500 ,
142+ 'type ' => HttpApiProblem::TYPE_HTTP_RFC ,
143+ 'title ' => HttpApiProblem::getTitleForStatusCode (500 ),
144+ 'detail ' => $ message ,
145+ ]);
146+ }
132147}
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public function __construct(Throwable $exception)
1818 {
1919 $ this ->exception = $ exception ;
2020 $ exceptionCode = $ exception ->getCode ();
21- $ statusCode = $ exceptionCode >= 400 && $ exceptionCode <= 599
21+ $ statusCode = is_int ( $ exception ) && $ exceptionCode >= 400 && $ exceptionCode <= 599
2222 ? $ exceptionCode
2323 : 500 ;
2424
You can’t perform that action at this time.
0 commit comments