Split try catch to prevent undefined variables

This commit is contained in:
Alejandro Celaya 2018-05-01 19:38:44 +02:00
parent e5e1aa2ff4
commit a2294704e6
2 changed files with 8 additions and 7 deletions

View File

@ -1,7 +1,6 @@
<?php
declare(strict_types=1);
use Fig\Http\Message\RequestMethodInterface as RequestMethod;
use Shlinkio\Shlink\Rest\Action;
return [

View File

@ -57,7 +57,15 @@ abstract class AbstractCreateShortCodeAction extends AbstractRestAction
$shortCodeMeta = $shortCodeData->getMeta();
$longUrl = $shortCodeData->getLongUrl();
$customSlug = $shortCodeMeta->getCustomSlug();
} catch (ValidationException | InvalidArgumentException $e) {
$this->logger->warning('Provided data is invalid.' . PHP_EOL . $e);
return new JsonResponse([
'error' => RestUtils::INVALID_ARGUMENT_ERROR,
'message' => $this->translator->translate('Provided data is invalid'),
], self::STATUS_BAD_REQUEST);
}
try {
$shortCode = $this->urlShortener->urlToShortCode(
$longUrl,
$shortCodeData->getTags(),
@ -94,12 +102,6 @@ abstract class AbstractCreateShortCodeAction extends AbstractRestAction
$customSlug
),
], self::STATUS_BAD_REQUEST);
} catch (ValidationException | InvalidArgumentException $e) {
$this->logger->warning('Provided data is invalid.' . PHP_EOL . $e);
return new JsonResponse([
'error' => RestUtils::INVALID_ARGUMENT_ERROR,
'message' => $this->translator->translate('Provided data is invalid'),
], self::STATUS_BAD_REQUEST);
} catch (\Throwable $e) {
$this->logger->error('Unexpected error creating shortcode.' . PHP_EOL . $e);
return new JsonResponse([