Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): improve error handling for MaterialTable #3465

Merged
merged 8 commits into from
May 22, 2023

Conversation

usu
Copy link
Member

@usu usu commented May 16, 2023

  • Fixes a few frontend issues around MaterialTable reported in Sentry (I accidentally removed the sentry reports so cannot link to them now - I'm sure they appear relatively soon on prod again)
  • Also: improves display of ServerErrors (rely on the same translation logic which Bacluc already implemented in Translations in the backend #2902)
  • Also: report ServerErrors in MaterialTable explicitly via Sentry (they are unexpected in the frontend and should be reported)
  • Also: fixes an issue with singular/plural in the violations translation from the API

Also fixes #3349: HttpException are now not excluded blindly anymore, but only if they equal to specific HTTP codes (excluded_http_codes). At the moment this is configured to exclude the following codes:
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
405 Method Not Allowed
422 Unprocessable Entity

However, this works only for exceptions of type HttpException. There are other exceptions that eventually respond with a 4xx status code. These exceptions still need to be excluded manually with ignore_exceptions

Before

image image

After

The following screenshot is only intended to visualize the change in error display and translation. This would not be reproducible anymore after this PR, because input length is already limited to 64 characters.
image

@usu usu force-pushed the fix/material-items branch from 034d161 to b0f84e8 Compare May 16, 2023 20:03
@usu usu marked this pull request as ready for review May 16, 2023 20:36
@usu usu requested review from BacLuc and carlobeltrame May 16, 2023 20:36
@usu
Copy link
Member Author

usu commented May 16, 2023

  • Also: report ServerErrors in MaterialTable explicitly via Sentry (they are unexpected in the frontend and should be reported)

I thought about generalizing this and include sentry reporting for each ServerError. I came to the conclusion that this is not very wise: Sometimes, server errors are part of the expected use case. Only the individual component can understand, if server errors are expected or not, so it should be the individual components responsibility to report unexpected server errors. Other opinions highly welcome.

Copy link
Member

@carlobeltrame carlobeltrame left a comment

Choose a reason for hiding this comment

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

I have some trouble seeing the big picture (tired right now), but the individual changes look good to me

@@ -11,7 +11,6 @@
ref="quantity"
v-model="materialItem.quantity"
dense
vee-rules="numeric"
Copy link
Member

Choose a reason for hiding this comment

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

Is that no longer useful?

Copy link
Member Author

Choose a reason for hiding this comment

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

Numeric only allows integer values. Our API allows float values. There's a built-in validation rule called "double" for float values. However, the "double" validation fails for empty values, which we explicitly allow.

Because we already set the html attribute type="number", the validation is not really needed, because the user cannot enter anything else than numbers anyway.

@usu
Copy link
Member Author

usu commented May 16, 2023

I have some trouble seeing the big picture (tired right now), but the individual changes look good to me

🤣 Bigger picture = Tried to fix some of the top-sentry issues on prod (on the API) from the last weeks and then went a bit down a rabbit hole when looking at how server errors are treated & displayed in the frontend.

@@ -50,7 +50,10 @@ public function normalize(mixed $object, string $format = null, array $context =

$translations = $this->translateToAllLocalesService->translate(
$violation->getMessageTemplate(),
$violation->getParameters()
array_merge(
$violation->getPlural() ? ['%count%' => $violation->getPlural()] : [],
Copy link
Contributor

Choose a reason for hiding this comment

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

I did not see directly in which case you needed this.
A test which covers this path would be nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Test added in f4baba3

Many symfony internal validators have violations messages that have a singular and a plural version. The %count% parameter needs to be provided to the translator such that it selects the right version:
https://github.com/symfony/symfony/blob/6.3/src/Symfony/Contracts/Translation/TranslatorInterface.php#L22
https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php#L123

Without this adjustment, the output would be the following (both singular+plural version returned):

'translations' => [
    'en' => 'This value is too long. It should have 32 character or less.|This value is too long. It should have 32 characters or less.',
    'de' => 'Diese Zeichenkette ist zu lang. Sie sollte höchstens 32 Zeichen haben.|Diese Zeichenkette ist zu lang. Sie sollte höchstens 32 Zeichen haben.',
    'fr' => 'Cette chaîne est trop longue. Elle doit avoir au maximum 32 caractère.|Cette chaîne est trop longue. Elle doit avoir au maximum 32 caractères.',
    'it' => 'Questo valore è troppo lungo. Dovrebbe essere al massimo di 32 carattere.|Questo valore è troppo lungo. Dovrebbe essere al massimo di 32 caratteri.',
],

@carlobeltrame carlobeltrame merged commit 5e210c0 into ecamp:devel May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants