provide better message when texture is missing

This commit is contained in:
Pig Fang 2020-08-19 18:34:17 +08:00
parent fe1a03fd8f
commit d10bcae197
No known key found for this signature in database
GPG Key ID: A8198F548DADA9E2
2 changed files with 18 additions and 1 deletions

View File

@ -2,6 +2,7 @@
namespace App\Exceptions;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
@ -16,12 +17,24 @@ class Handler extends ExceptionHandler
\Illuminate\Auth\AuthenticationException::class,
\Illuminate\Auth\Access\AuthorizationException::class,
\Symfony\Component\HttpKernel\Exception\HttpException::class,
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
\Illuminate\Validation\ValidationException::class,
\Illuminate\Session\TokenMismatchException::class,
ModelNotFoundException::class,
PrettyPageException::class,
];
public function render($request, Throwable $exception)
{
if ($exception instanceof ModelNotFoundException) {
$model = $exception->getModel();
if (Str::endsWith($model, 'Texture')) {
$exception = new ModelNotFoundException(trans('skinlib.non-existent'));
}
}
return parent::render($request, $exception);
}
protected function convertExceptionToArray(Throwable $e)
{
return [

View File

@ -210,6 +210,10 @@ class SkinlibControllerTest extends TestCase
public function testInfo()
{
$this->get(route('texture.info', ['texture' => 0]))
->assertNotFound()
->assertSee(trans('skinlib.non-existent'));
$texture = factory(Texture::class)->create();
$this->get(route('texture.info', ['texture' => $texture]))
->assertJson($texture->toArray());