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

Closes #45 - global handlers for most-specific exceptions & fine-grained logging #494

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bruderj15
Copy link
Member

The Quality-Gate fails due to test-coverage.
However, unit-testing a global exception handler seems useless as integration with controllers is key.
Therefore, adding tests for exception handling in controllers acceptance- and integrationtests should be considered.

Thanks for your PR! Please fill out the following list :)


  • I put the ticket or multiple tickets in review
  • Commit message format → Closes #<Issue Number> - Your commit message.
  • Sonarcloud link : Not available, Quality-Gate can be seen in CI: https://github.com/bruderj15/kadai-fork/runs/36345898177
  • No documentation update needed
  • Link to PR with documentation update: <add the link here>
  • No Release Notes needed
  • Release Notes :

@bruderj15 bruderj15 linked an issue Jan 29, 2025 that may be closed by this pull request
Copy link
Contributor

@CRoberto1926 CRoberto1926 left a comment

Choose a reason for hiding this comment

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

Did you briefly test with frontend?

String.format("Error occurred during processing of rest request: %s", errorData), ex);

switch (status.series()) {
case CLIENT_ERROR -> logger.warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be an error and not a warn

Copy link
Member Author

Choose a reason for hiding this comment

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

I strongly disagree.
Consider a client trying to request an endpoint not existing.
Is this an error? No. Errors are states intended never to be reached.

Contrarily, one could even argue if this is even worth a warning.
Many people do log it informational.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I strongly disagree about exceptions not logged as errors ;) but your argument is valid. Warning may be fine

String.format("Exception thrown during processing of rest request: %s", errorData));
case SERVER_ERROR -> logger.error(
String.format("Error occurred during processing of rest request: %s", errorData), ex);
default -> logger.warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be an error and not a warn

Copy link
Member Author

@bruderj15 bruderj15 Jan 31, 2025

Choose a reason for hiding this comment

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

Making this an error would contradict the semantics of the HTTP codes.
It cannot be 4xx nor 5xx because those are checked already.

Therefore it must be either 1xx, 2xx or 3xx, which none of indicate faulty behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

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

you`re right

ErrorCode.of(ERROR_KEY_UNKNOWN_ERROR), HttpStatus.INTERNAL_SERVER_ERROR, ex, req);
logger.error(
String.format("Unknown error occurred during processing of rest request: %s", errorData),
ex);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to log this stacktrace?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, as it points to us failing to provide a specific handler for an exception, indicating missing thoughts around the implementation.
The question then is, which implementation and where?
The stack trace answers immediately.

Take into perspective that this does not pollute the logs, because we should always handle the most-specific exceptions.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

@bruderj15
Copy link
Member Author

Did you briefly test with frontend?

No, semantics shall not change with this PR and all tests passed.
Manually testing would undermine the relevance of the automated tests.

@CRoberto1926
Copy link
Contributor

Did you briefly test with frontend?

No, semantics shall not change with this PR and all tests passed. Manually testing would undermine the relevance of the automated tests.

I don't think manually testing undermines anything :)

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.

Unnecessarily printed stacktraces in REST API
2 participants