Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions Controller/WebUIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(
public function indexAction(?string $configName = null): Response
{
if (!$this->isWebUIEnabled) {
return new Response('You are not allowed here. Check you config. ', 400);
return new Response('You are not allowed here. Check your config.', Response::HTTP_BAD_REQUEST);
}

$config = $this->configurationManager->getConfiguration($configName);
Expand Down Expand Up @@ -124,7 +124,7 @@ public function indexAction(?string $configName = null): Response
public function showAction(string $configName, string $locale, string $domain): Response
{
if (!$this->isWebUIEnabled) {
return new Response('You are not allowed here. Check you config. ', 400);
return new Response('You are not allowed here. Check your config.', Response::HTTP_BAD_REQUEST);
}
$config = $this->configurationManager->getConfiguration($configName);

Expand Down Expand Up @@ -154,7 +154,7 @@ public function showAction(string $configName, string $locale, string $domain):
public function createAction(Request $request, string $configName, string $locale, string $domain): Response
{
if (!$this->isWebUIEnabled || !$this->isWebUIAllowCreate) {
return new Response('You are not allowed to create. Check you config. ', 400);
return new Response('You are not allowed to create. Check your config.', Response::HTTP_BAD_REQUEST);
}

/** @var StorageService $storage */
Expand All @@ -166,13 +166,15 @@ public function createAction(Request $request, string $configName, string $local
$message = $message->withLocale($locale);
$this->validateMessage($message, ['Create']);
} catch (MessageValidationException $e) {
return new Response($e->getMessage(), 400);
return new Response($e->getMessage(), Response::HTTP_BAD_REQUEST);
}

try {
$storage->create($message);
} catch (StorageException $e) {
throw new BadRequestHttpException(\sprintf('Key "%s" does already exist for "%s" on domain "%s".', $message->getKey(), $locale, $domain), $e);
} catch (\Exception $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really the behavior we're looking for? I'm afraid hiding all exceptions like this will make debugging much harder in case we have a problem in a storage isn't it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this comment also applies for all others storage method calls (update & delete).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the catch statement you see only Unknown error. in the UI. IMO this hides the actual problem even more.

return new Response($e->getMessage(), Response::HTTP_BAD_REQUEST);
}

return $this->render('@Translation/WebUI/create.html.twig', [
Expand All @@ -183,7 +185,7 @@ public function createAction(Request $request, string $configName, string $local
public function editAction(Request $request, string $configName, string $locale, string $domain): Response
{
if (!$this->isWebUIEnabled) {
return new Response('You are not allowed here. Check you config. ', 400);
return new Response('You are not allowed here. Check your config.', Response::HTTP_BAD_REQUEST);
}

try {
Expand All @@ -192,20 +194,24 @@ public function editAction(Request $request, string $configName, string $locale,
$message = $message->withLocale($locale);
$this->validateMessage($message, ['Edit']);
} catch (MessageValidationException $e) {
return new Response($e->getMessage(), 400);
return new Response($e->getMessage(), Response::HTTP_BAD_REQUEST);
}

/** @var StorageService $storage */
$storage = $this->storageManager->getStorage($configName);
$storage->update($message);
try {
$storage->update($message);
} catch (\Exception $e) {
return new Response($e->getMessage(), Response::HTTP_BAD_REQUEST);
}

return new Response('Translation updated');
}

public function deleteAction(Request $request, string $configName, string $locale, string $domain): Response
{
if (!$this->isWebUIEnabled || !$this->isWebUIAllowDelete) {
return new Response('You are not allowed to create. Check you config. ', 400);
return new Response('You are not allowed to create. Check your config.', Response::HTTP_BAD_REQUEST);
}

try {
Expand All @@ -214,12 +220,16 @@ public function deleteAction(Request $request, string $configName, string $local
$message = $message->withDomain($domain);
$this->validateMessage($message, ['Delete']);
} catch (MessageValidationException $e) {
return new Response($e->getMessage(), 400);
return new Response($e->getMessage(), Response::HTTP_BAD_REQUEST);
}

/** @var StorageService $storage */
$storage = $this->storageManager->getStorage($configName);
$storage->delete($locale, $domain, $message->getKey());
try {
$storage->delete($locale, $domain, $message->getKey());
} catch (\Exception $e) {
return new Response($e->getMessage(), Response::HTTP_BAD_REQUEST);
}

return new Response('Message was deleted');
}
Expand Down