mirror of
https://github.com/shlinkio/shlink.git
synced 2025-05-06 07:15:12 +03:00
Split try catch to prevent undefined variables
This commit is contained in:
parent
e5e1aa2ff4
commit
a2294704e6
2 changed files with 8 additions and 7 deletions
module/Rest/src/Action/ShortCode
|
@ -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([
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue