1414 * @link https://github.com/MarcinOrlowski/laravel-api-response-builder
1515 */
1616
17- use Exception ;
17+ use Throwable ;
1818use Illuminate \Auth \AuthenticationException as AuthException ;
1919use Illuminate \Support \Facades \Config ;
2020use Illuminate \Support \Facades \Lang ;
@@ -33,11 +33,11 @@ class ExceptionHandlerHelper
3333 * Render an exception into valid API response.
3434 *
3535 * @param \Illuminate\Http\Request $request Request object
36- * @param \Exception $ex Exception
36+ * @param \Throwable $ex Throwable to handle
3737 *
3838 * @return HttpResponse
3939 */
40- public static function render (/** @scrutinizer ignore-unused */ $ request , Exception $ ex ): HttpResponse
40+ public static function render (/** @scrutinizer ignore-unused */ $ request , \ Throwable $ ex ): HttpResponse
4141 {
4242 $ result = null ;
4343
@@ -62,17 +62,17 @@ public static function render(/** @scrutinizer ignore-unused */ $request, Except
6262 }
6363
6464 /**
65- * Handles given exception and produces valid HTTP response object.
65+ * Handles given throwable and produces valid HTTP response object.
6666 *
67- * @param \Exception $ex Exception to be handled.
67+ * @param \Throwable $ex Throwable to be handled.
6868 * @param array $ex_cfg ExceptionHandler's config excerpt related to $ex exception type.
6969 * @param int $fallback_http_code HTTP code to be assigned to produced $ex related response in
7070 * case configuration array lacks own `http_code` value. Default
7171 * HttpResponse::HTTP_INTERNAL_SERVER_ERROR
7272 *
7373 * @return \Symfony\Component\HttpFoundation\Response
7474 */
75- protected static function processException (\Exception $ ex , array $ ex_cfg ,
75+ protected static function processException (\Throwable $ ex , array $ ex_cfg ,
7676 int $ fallback_http_code = HttpResponse::HTTP_INTERNAL_SERVER_ERROR )
7777 {
7878 $ api_code = $ ex_cfg ['api_code ' ];
@@ -110,13 +110,13 @@ protected static function processException(\Exception $ex, array $ex_cfg,
110110 * `default` handler either for HttpException (if $ex is instance of it), or generic `default`
111111 * config.
112112 *
113- * @param \Exception $ex
113+ * @param \Throwable $ex
114114 * @param int $http_code
115115 * @param array $placeholders
116116 *
117117 * @return string
118118 */
119- protected static function getErrorMessageForException (\Exception $ ex , int $ http_code , array $ placeholders ): string
119+ protected static function getErrorMessageForException (\Throwable $ ex , int $ http_code , array $ placeholders ): string
120120 {
121121 // exception message is uselss, lets go deeper
122122 if ($ ex instanceof HttpException) {
@@ -153,14 +153,14 @@ protected function unauthenticated(/** @scrutinizer ignore-unused */ $request,
153153 /**
154154 * Process single error and produce valid API response.
155155 *
156- * @param Exception $ex Exception to be handled.
156+ * @param \Throwable $ex Exception to be handled.
157157 * @param integer $api_code
158158 * @param integer $http_code
159159 * @param string $error_message
160160 *
161161 * @return HttpResponse
162162 */
163- protected static function error (Exception $ ex ,
163+ protected static function error (Throwable $ ex ,
164164 int $ api_code , int $ http_code = null , string $ error_message = null ): HttpResponse
165165 {
166166 $ ex_http_code = ($ ex instanceof HttpException) ? $ ex ->getStatusCode () : $ ex ->getCode ();
@@ -265,7 +265,7 @@ protected static function getExceptionHandlerConfig(): array
265265 *
266266 * @return array|null
267267 */
268- protected static function getHandler (Exception $ ex ): ?array
268+ protected static function getHandler (\ Throwable $ ex ): ?array
269269 {
270270 $ result = null ;
271271
0 commit comments