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', ], /*