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

When getting locale message, default locale to LocaleContextHolder when locale is null #7516

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

ianwallen
Copy link
Contributor

When getting locale message, default locale to LocaleContextHolder when locale is null

It was noticed that if we did something like the following when calling an api.

throw new WebApplicationException().withMessageKey("message.key"));

The API Error would contain the message based on the key as follow

"message.key"

The reason for this is because no locale was identified in the exception. If we do the following
 
throw new WebApplicationException().withMessageKey("message.key").withLocale(LocaleContextHolder.getLocale());

Then the API Error would contain the message on the key as follow

"Some Text for locale"

Since it is better to show text to the end users instead of showing the message key, this PR will default the message key to LocaleContextHolder.getLocale() automatically so that we don't need to supply it for each exception raised.

Checklist

  • I have read the [contribution guidelines](https://github.com/geonetwork/core-geonetwork/blob/main/CONTRIBUTING.md
  • Pull request provided for main branch, backports managed with label
  • Good housekeeping of code, cleaning up comments, tests, and documentation
  • Clean commit history broken into understandable chucks, avoiding big commits with hundreds of files, cautious of reformatting and whitespace changes
  • Clean commit messages, longer verbose messages are encouraged
  • API Changes are identified in commit messages
  • Testing provided for features or enhancements using automatic tests)
  • User documentation provided for new features or enhancements in mannual
  • Build documentation provided for development instructions in README.md files
  • Library management using pom.xml dependency management. Update build documentation with intended library use and library tutorials or documentation

@josegar74
Copy link
Member

Thanks @ianwallen. I notice the issue working with #7519, but didn't have time to investigate further.

@ianwallen
Copy link
Contributor Author

Fixed issue related to code smell

Copy link

sonarcloud bot commented Nov 28, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.21) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

@josegar74 josegar74 merged commit d77409e into main Nov 30, 2023
10 checks passed
@ianwallen ianwallen deleted the default_locale branch November 30, 2023 13:18
ianwallen added a commit that referenced this pull request Nov 30, 2023
ianwallen added a commit that referenced this pull request Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants