Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Enhancement/refactor exceptions [FIXES #32] #33

Merged
merged 12 commits into from
Sep 30, 2020
Merged

Enhancement/refactor exceptions [FIXES #32] #33

merged 12 commits into from
Sep 30, 2020

Conversation

osopromadze
Copy link
Contributor

fixes #32

Moved all exceptions into the same package. They are extended from BaseException class. Created messages.properties in resources/i18n folder, and exceptions get error messages from that file. Created global exception handler class and there is constructing final output error object with status code, timestamp and message.

@chaoran-chen
Copy link
Member

Hello @osopromadze, thank you very much for this PR! It looks great at a first glance. We will review it in the next few days and give an answer at the beginning of next week.

@osopromadze
Copy link
Contributor Author

osopromadze commented Sep 26, 2020

Great @chaoran-chen, thanks for letting me know 👍

@chaoran-chen
Copy link
Member

Hi. Would it be possible to remove projectlombok from the dependencies since we are also not using it in the other classes? But the library is very nice and maybe we will introduce it consistently for the whole project at a later point in time.

Copy link
Contributor

@dajenet dajenet left a comment

Choose a reason for hiding this comment

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

Hi @osopromadze, thank you for your PR. It looks good. I just added a few comments.

@@ -132,7 +137,7 @@ public int createAccount(RegistrationRequest registration) throws AccountCreatio
*/
public String login(Account account) {
if (account.getId() != null) {
throw new IllegalArgumentException("The account id is not null.");
throw new AccountCreationException().withErrorCode(ErrorCodeEnum.ERR_ACC_002);
Copy link
Contributor

Choose a reason for hiding this comment

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

This has nothing to do with account creation. So maybe better use a IllegalArgumentException or IllegalRequestParameterException.

DeviceAvailabilityCreationException.class,
IllegalRequestParameterException.class
})
public ResponseEntity<Object> handleAccountCreationException(HttpServletRequest request, BaseException exception, Locale locale) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Because you are handling different exceptions here it would be better to choose a more general method name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dajenet good idea choosing more general name, or handle different type of exceptions in different methods, but as method body is same thats why I put them in same. Feel free to change it as you consider.

@osopromadze
Copy link
Contributor Author

Hi. Would it be possible to remove projectlombok from the dependencies since we are also not using it in the other classes? But the library is very nice and maybe we will introduce it consistently for the whole project at a later point in time.

Yes, no problem, Just added project lombok to easily generate constructros, or getters and setters. Can be removed easily and write code without it.

Copy link
Member

@chaoran-chen chaoran-chen left a comment

Choose a reason for hiding this comment

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

The import in src/test/java/science/icebreaker/device_availability/DeviceAvailabilityServiceTest.java#20 needs to be adapted since the DeviceAvailabilityCreationException was moved. And for consistency, DeviceAvailabilityNotFoundException should also be moved to the science.icebreaker.exception package.

@osopromadze
Copy link
Contributor Author

The import in src/test/java/science/icebreaker/device_availability/DeviceAvailabilityServiceTest.java#20 needs to be adapted since the DeviceAvailabilityCreationException was moved. And for consistency, DeviceAvailabilityNotFoundException should also be moved to the science.icebreaker.exception package.

@chaoran-chen done. All tests passed and moved DeviceAvailabilityNotFoundException in exception package.

Copy link
Member

@chaoran-chen chaoran-chen left a comment

Choose a reason for hiding this comment

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

Great. Thank you!

@chaoran-chen chaoran-chen merged commit a3e2127 into icebreaker-science:develop Sep 30, 2020
@osopromadze osopromadze deleted the enhancement/refactor_exceptions branch September 30, 2020 14:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactoring
3 participants