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

exception handling update #13

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task<User> GetUserByEmail(string email)
public async Task<GetUserDto?> UpdateUser(UpdateUserDto updateUserDto, string email)
{
var userToUpdate = await userRepository.GetUserByEmail(email);
if (userToUpdate == null) return null;
if (userToUpdate == null) throw new NotFoundException("User not found");

if (updateUserDto.Username != null && !updateUserDto.Username.Equals(string.Empty))
{
Expand Down
11 changes: 3 additions & 8 deletions api/Events/User/ClientWantsToUpdateProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,16 @@ public class ClientWantsToUpdateProfile (UserService userService, JwtService jwt
public override async Task Handle(ClientWantsToUpdateUserDto dto, IWebSocketConnection socket)
{
var email = jwtService.GetEmailFromJwt(dto.Jwt);
var getUserDto = await userService.UpdateUser(dto.UpdateUserDto, email);

if (getUserDto != null)
try
{
var getUserDto = await userService.UpdateUser(dto.UpdateUserDto, email);
socket.SendDto(new ServerConfirmsUpdate
{
GetUserDto = getUserDto
});
}
else
} catch (Exception e) when (e is not NotFoundException)
{
var user = await userService.GetUserByEmail(email);

if (user == null) throw new NotFoundException("User not found");

socket.SendDto(new ServerRejectsUpdate
{
ErrorMessage = "Update failed",
Expand Down
Loading