-
Notifications
You must be signed in to change notification settings - Fork 106
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
Sending valid error messages from backend during sign in/ signup to the forntend #201
Sending valid error messages from backend during sign in/ signup to the forntend #201
Conversation
Codecov Report
@@ Coverage Diff @@
## master #201 +/- ##
============================================
- Coverage 67.48% 67.44% -0.05%
- Complexity 170 171 +1
============================================
Files 27 31 +4
Lines 732 728 -4
Branches 31 29 -2
============================================
- Hits 494 491 -3
+ Misses 230 229 -1
Partials 8 8
Continue to review full report at Codecov.
|
@piotrkosinski1992 Can you please resolve the conflicts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- There are some changes needed described in comments
- Rebase is needed to resolve conflicts
- Please name PR and commit messages as described in CONTRIBUTTING.MD
@@ -30,13 +30,6 @@ paths: | |||
responses: | |||
'201': | |||
description: "if user created" | |||
content: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
import javax.annotation.Generated; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Generated( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we have those mappers in service/src/main/generated
?
They were under service/build/generated
and not tracked by git
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
@ControllerAdvice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about RestControllerAdvice
?
https://stackoverflow.com/a/43124517/5785871
assertEquals(response, createdUserDto); | ||
assertEquals(0, createdUserDto.getCommunityIds().size()); | ||
verify(userRepository).findByEmail(request.getEmail()); | ||
verify(userRepository).save(User.builder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
|
||
// when | ||
Optional<UserDto> createdUserDto = userService.createUser(request); | ||
Exception exception = Assertions.assertThrows( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use static import for assertThrows
Optional<UserDto> createdUserDto = userService.createUser(request); | ||
Exception exception = Assertions.assertThrows( | ||
EmailAlreadyExistsException.class, | ||
() -> userService.createUser(request)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move );
to the new line
@@ -179,11 +188,34 @@ void getUserDetailsNotFound() { | |||
.willReturn(Optional.empty()); | |||
|
|||
// when | |||
Optional<UserDto> createdUserDto = userService.getUserDetails(USER_ID); | |||
Exception exception = Assertions.assertThrows( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use static import
} else { | ||
return Optional.empty(); | ||
@Override public void createUser(UserDto dto) { | ||
verifyEmailUniqueness(dto); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's wrap it in optional and use filter/orElse rather than putting that in void methods
private UserDto createUserInRepository(UserDto request) { | ||
User user = userMapper.userDtoToUser(request); | ||
User savedUser = userRepository.save(user); | ||
private void saveUser(UserDto request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's return the UserDto
from this method and also from the service.
Just ignore it in UserController
.
That would:
- be easier to tests
- will not have magic logic inside void methods
- will be more functional approach
@ControllerAdvice | ||
public class ApiErrorHandler { | ||
|
||
@ExceptionHandler(value = { Exception.class }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's pass here all the exceptions that we throw in application and create handleException method per each HTTP code that we want to return - we will do not have to manage the http codes in exception descriptions.
Non handled exceptions should be handled as INTERNAL_SERVER_ERROR (500 code)
Closing - no feedback from contributor |
🚀 Description
#199
Sorry for formatting on generated mapstruct files
📄 Motivation and Context
Fixes Issue #199