mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-17 05:28:18 +01:00
Added new exception interface and updated transformers
This commit is contained in:
parent
b9ca5f7066
commit
6efe100064
22
app/Exceptions/ExceptionInterface.php
Normal file
22
app/Exceptions/ExceptionInterface.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Exceptions;
|
||||
|
||||
/**
|
||||
* This is the exception interface.
|
||||
*
|
||||
* @author Graham Campbell <graham@alt-three.com>
|
||||
*/
|
||||
interface ExceptionInterface
|
||||
{
|
||||
//
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
* This file is part of StyleCI.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
@ -11,17 +11,19 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Exceptions\Transformers;
|
||||
|
||||
use CachetHQ\Cachet\Exceptions\ExceptionInterface;
|
||||
use Exception;
|
||||
use GrahamCampbell\Exceptions\Transformers\TransformerInterface;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* This is the model not found transformer class.
|
||||
* This is the exception transformer class.
|
||||
*
|
||||
* @author Graham Campbell <graham@alt-three.com>
|
||||
*/
|
||||
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;
|
@ -27,7 +27,7 @@ return [
|
||||
|
||||
'transformers' => [
|
||||
'GrahamCampbell\Exceptions\Transformers\CsrfTransformer',
|
||||
'CachetHQ\Cachet\Exceptions\Transformers\ModelNotFoundTransformer',
|
||||
'CachetHQ\Cachet\Exceptions\Transformers\ExceptionTransformer',
|
||||
],
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user