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

Sending valid error messages from backend during sign in/ signup to the forntend #201

Conversation

piotrkosinski137
Copy link

🚀 Description

#199
Sorry for formatting on generated mapstruct files

📄 Motivation and Context
Fixes Issue #199

@codecov
Copy link

codecov bot commented Oct 23, 2020

Codecov Report

Merging #201 into master will decrease coverage by 0.04%.
The diff coverage is 60.60%.

Impacted file tree graph

@@             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              
Impacted Files Coverage Δ Complexity Δ
...n/java/com/myhome/controllers/ApiErrorHandler.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...java/com/myhome/security/AppUserDetailFetcher.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...ava/com/myhome/security/AppUserDetailsService.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...a/com/myhome/security/AuthenticationException.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...om/myhome/security/MyHomeAuthenticationFilter.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...in/java/com/myhome/controllers/UserController.java 100.00% <100.00%> (ø) 4.00 <0.00> (-3.00)
...yhome/services/springdatajpa/UserSDJpaService.java 100.00% <100.00%> (+8.00%) 11.00 <6.00> (+2.00)
...atajpa/exceptions/EmailAlreadyExistsException.java 100.00% <100.00%> (ø) 1.00 <1.00> (?)
...pringdatajpa/exceptions/UserNotFoundException.java 100.00% <100.00%> (ø) 1.00 <1.00> (?)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cdeefa5...d22fb4f. Read the comment docs.

@piotrkosinski137 piotrkosinski137 changed the title Issue 199 Sending valid error messages from backend during sign in/ signup to the forntend Sending valid error messages from backend during sign in/ signup to the forntend Oct 23, 2020
@jmprathab
Copy link
Owner

@piotrkosinski1992 Can you please resolve the conflicts?

Copy link
Collaborator

@mslowiak mslowiak left a 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:
Copy link
Collaborator

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(
Copy link
Collaborator

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
Copy link
Collaborator

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()
Copy link
Collaborator

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(
Copy link
Collaborator

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));
Copy link
Collaborator

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(
Copy link
Collaborator

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);
Copy link
Collaborator

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) {
Copy link
Collaborator

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 })
Copy link
Collaborator

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)

@mslowiak mslowiak added the awaiting-review-changes Awaiting for PR owner to make changes label Oct 31, 2020
@piotrkosinski137 piotrkosinski137 removed their assignment Nov 10, 2020
@mslowiak
Copy link
Collaborator

Closing - no feedback from contributor

@mslowiak mslowiak closed this Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review-changes Awaiting for PR owner to make changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sending valid error messages from backend during sign in/ signup to the forntend
3 participants