From 6efe100064e0a1e6638b2ccfcf6e9796d1814d8a Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 6 Dec 2015 17:59:26 +0000 Subject: [PATCH] Added new exception interface and updated transformers --- app/Exceptions/ExceptionInterface.php | 22 +++++++++++++++++++ ...ansformer.php => ExceptionTransformer.php} | 14 +++++++----- config/exceptions.php | 2 +- 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 app/Exceptions/ExceptionInterface.php rename app/Exceptions/Transformers/{ModelNotFoundTransformer.php => ExceptionTransformer.php} (63%) diff --git a/app/Exceptions/ExceptionInterface.php b/app/Exceptions/ExceptionInterface.php new file mode 100644 index 000000000..15ce0eee2 --- /dev/null +++ b/app/Exceptions/ExceptionInterface.php @@ -0,0 +1,22 @@ + + */ +interface ExceptionInterface +{ + // +} diff --git a/app/Exceptions/Transformers/ModelNotFoundTransformer.php b/app/Exceptions/Transformers/ExceptionTransformer.php similarity index 63% rename from app/Exceptions/Transformers/ModelNotFoundTransformer.php rename to app/Exceptions/Transformers/ExceptionTransformer.php index 69ea37ba6..cd8fc267f 100644 --- a/app/Exceptions/Transformers/ModelNotFoundTransformer.php +++ b/app/Exceptions/Transformers/ExceptionTransformer.php @@ -1,7 +1,7 @@ */ -class ModelNotFoundTransformer implements TransformerInterface +class ExceptionTransformer implements TransformerInterface { /** * Transform the provided exception. @@ -32,8 +34,10 @@ class ModelNotFoundTransformer implements TransformerInterface */ public function transform(Exception $exception) { - if ($exception instanceof ModelNotFoundException) { - $exception = new NotFoundHttpException('Resource not found'); + if ($exception instanceof ExceptionInterface) { + $exception = new BadRequestHttpException($exception->getMessage()); + } elseif ($exception instanceof ModelNotFoundException) { + $exception = new NotFoundHttpException('Resource not found.'); } return $exception; diff --git a/config/exceptions.php b/config/exceptions.php index 06dcaffef..11064dd63 100644 --- a/config/exceptions.php +++ b/config/exceptions.php @@ -27,7 +27,7 @@ return [ 'transformers' => [ 'GrahamCampbell\Exceptions\Transformers\CsrfTransformer', - 'CachetHQ\Cachet\Exceptions\Transformers\ModelNotFoundTransformer', + 'CachetHQ\Cachet\Exceptions\Transformers\ExceptionTransformer', ], /*