Skip to content

Conversation

@Guite
Copy link
Contributor

@Guite Guite commented Jan 17, 2020

This PR ensures that exception messages are returned with status code 400 so they are shown in the Web UI instead of Unknown error..
It also replaces the 400 number by the corresponding Response constant.

$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.

@odolbeau
Copy link
Member

Hi @Guite & thanks for your contribution.

What's exactly the current behavior when an error occurred when interacting with the storage?
Does the Unknown error also comes with a stacktrace?

@Guite
Copy link
Contributor Author

Guite commented Jan 17, 2020

Behaviour without this PR:

Screenshot_20200117_135500

Behaviour with this PR:

Screenshot_20200117_135605

@Guite
Copy link
Contributor Author

Guite commented Jan 17, 2020

I could also change it to return BadRequestHttpException(...) instead of return new Response(..., Response::HTTP_BAD_REQUEST);. This would combine the new behaviour with a stack trace I think.

@odolbeau
Copy link
Member

I could also change it to return BadRequestHttpException(...) instead of return new Response(..., Response::HTTP_BAD_REQUEST);. This would combine the new behaviour with a stack trace I think.

The new message is great but it would be even better if we could keep the stacktrace! 🙏

@Guite
Copy link
Contributor Author

Guite commented Jan 17, 2020

Doesn't work unfortunately: it shows the entire stack trace inside the Bootstrap alert then.

@odolbeau
Copy link
Member

I don't know what to choose: with your changes, the end user message is way better and will ease resolving most of possible errors. On the other hand, we loose the stacktrace which can help a lot in some cases...
Let's wait for some others opinions, both solution are OK for me.

@Guite
Copy link
Contributor Author

Guite commented Jan 17, 2020

My intention was that in production systems a user of the WebUI may experience problems which are not caused by programming errors. For example missing permissions like in the screenshots above or other server or config related issues.

@Nyholm
Copy link
Member

Nyholm commented Jan 18, 2020

I like the new messages.

But as @odolbeau points out, no solution is perfect. We should maybe look over this to see if there is a different way to solve this problem.

Im happy with merging this for now.

@Nyholm Nyholm merged commit 0f9cddc into php-translation:master Jan 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants