From 55e6a6c10bf36e4d582a0166d92a881a1bf93f93 Mon Sep 17 00:00:00 2001 From: Bayu Hendra Winata Date: Sat, 11 Jan 2020 22:17:12 +0700 Subject: [PATCH] add helpers: capture_exception_and_abort --- src/helpers.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/helpers.php b/src/helpers.php index 02eb388..26e3c72 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -15,3 +15,22 @@ function capture_exception(Throwable $exception) } } } + +if (! function_exists('capture_exception_and_abort')) { + /** + * Capture and report exception + * + * @param Throwable $exception + * + * @return string + * @throws Throwable + */ + function capture_exception_and_abort(Throwable $exception) + { + capture_exception($exception); + if (config('app.debug')) { + throw $exception; + } + abort($exception->getCode(), $exception->getMessage()); + } +}