File tree 1 file changed +15
-3
lines changed
1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ protected function genericResponse(Throwable $exception)
183
183
184
184
$ response = $ this ->newResponseArray ();
185
185
186
- array_walk_recursive ($ response , function (&$ value , $ key ) use ($ exception , $ replacements ) {
186
+ array_walk_recursive ($ response , function (&$ value , $ key ) use ($ replacements ) {
187
187
if (Str::startsWith ($ value , ': ' ) && isset ($ replacements [$ value ])) {
188
188
$ value = $ replacements [$ value ];
189
189
}
@@ -203,11 +203,23 @@ protected function genericResponse(Throwable $exception)
203
203
*/
204
204
protected function getStatusCode (Throwable $ exception )
205
205
{
206
+ $ statusCode = null ;
207
+
206
208
if ($ exception instanceof ValidationException) {
207
- return $ exception ->status ;
209
+ $ statusCode = $ exception ->status ;
210
+ } elseif ($ exception instanceof HttpExceptionInterface) {
211
+ $ statusCode = $ exception ->getStatusCode ();
212
+ } else {
213
+ // By default throw 500
214
+ $ statusCode = 500 ;
215
+ }
216
+
217
+ // Be extra defensive
218
+ if ($ statusCode < 100 || $ statusCode > 500 ) {
219
+ $ statusCode = 500 ;
208
220
}
209
221
210
- return $ exception instanceof HttpExceptionInterface ? $ exception -> getStatusCode () : 500 ;
222
+ return $ statusCode ;
211
223
}
212
224
213
225
/**
You can’t perform that action at this time.
0 commit comments