From 98b6dba05d34cf2cf8a88db55b7f5a1044b83f0d Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 20 Nov 2019 20:21:02 +0100 Subject: [PATCH] Removed generic error handling from action that will usually be handled by ErrorHandler middleware --- .../ShortUrl/AbstractCreateShortUrlAction.php | 7 ------- .../Action/ShortUrl/CreateShortUrlActionTest.php | 16 ---------------- 2 files changed, 23 deletions(-) diff --git a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php index e55f564e..f3eaee19 100644 --- a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php @@ -15,7 +15,6 @@ use Shlinkio\Shlink\Core\Service\UrlShortenerInterface; use Shlinkio\Shlink\Core\Transformer\ShortUrlDataTransformer; use Shlinkio\Shlink\Rest\Action\AbstractRestAction; use Shlinkio\Shlink\Rest\Util\RestUtils; -use Throwable; use Zend\Diactoros\Response\JsonResponse; use function sprintf; @@ -74,12 +73,6 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction 'error' => RestUtils::getRestErrorCodeFromException($e), 'message' => sprintf('Provided slug %s is already in use. Try with a different one.', $customSlug), ], self::STATUS_BAD_REQUEST); - } catch (Throwable $e) { - $this->logger->error('Unexpected error creating short url. {e}', ['e' => $e]); - return new JsonResponse([ - 'error' => RestUtils::UNKNOWN_ERROR, - 'message' => 'Unexpected error occurred', - ], self::STATUS_INTERNAL_SERVER_ERROR); } } diff --git a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php index cea67f0f..732cbc25 100644 --- a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl; -use Exception; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -124,19 +123,4 @@ class CreateShortUrlActionTest extends TestCase $this->assertEquals(400, $response->getStatusCode()); $this->assertStringContainsString(RestUtils::INVALID_SLUG_ERROR, (string) $response->getBody()); } - - /** @test */ - public function aGenericExceptionWillReturnError(): void - { - $this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array'), Argument::cetera()) - ->willThrow(Exception::class) - ->shouldBeCalledOnce(); - - $request = (new ServerRequest())->withParsedBody([ - 'longUrl' => 'http://www.domain.com/foo/bar', - ]); - $response = $this->action->handle($request); - $this->assertEquals(500, $response->getStatusCode()); - $this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::UNKNOWN_ERROR) > 0); - } }