Files
cachet-docker/app/Exceptions/Transformers/ModelNotFoundTransformer.php
Graham Campbell bf05197c4f Cleanup exception handling
You're going to love this @joecohens and @jbrooksuk :)
2015-07-06 18:21:23 +01:00

42 lines
1017 B
PHP

<?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\Transformers;
use Exception;
use GrahamCampbell\Exceptions\Transformers\TransformerInterface;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpNotFoundException;
/**
* This is the model not found transformer class.
*
* @author Graham Campbell <graham@alt-three.com>
*/
class ModelNotFoundTransformer implements TransformerInterface
{
/**
* Transform the provided exception.
*
* @param \Exception $exception
*
* @return \Exception
*/
public function transform(Exception $exception)
{
if ($exception instanceof ModelNotFoundException) {
$exception = new HttpNotFoundException('Resource not found');
}
return $exception;
}
}