From 13ac5df5ee4a73d2d94ad170c6fbc754570486f7 Mon Sep 17 00:00:00 2001 From: Fredo <fredotanzil@gmail.com> Date: Thu, 27 Feb 2025 12:28:37 +0700 Subject: [PATCH] handle fail login email --- .../controller/AuthenticationController.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/safetypin/authentication/controller/AuthenticationController.java b/src/main/java/com/safetypin/authentication/controller/AuthenticationController.java index d7e04c0..ee3bcfc 100644 --- a/src/main/java/com/safetypin/authentication/controller/AuthenticationController.java +++ b/src/main/java/com/safetypin/authentication/controller/AuthenticationController.java @@ -65,16 +65,22 @@ public class AuthenticationController { try { return ResponseEntity.ok(authenticationService.loginUser(email, password)); } catch (InvalidCredentialsException e){ - return ResponseEntity.status(HttpStatus.UNAUTHORIZED) - .body(e.getMessage()); + AuthResponse response = new AuthResponse(false, e.getMessage(), null); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); } } // Endpoint for social login @PostMapping("/login-social") - public User loginSocial(@RequestParam String email) { - return authenticationService.loginSocial(email); + public ResponseEntity<Object> loginSocial(@RequestParam String email) { + try { + return ResponseEntity.ok(authenticationService.loginSocial(email)); + } catch (InvalidCredentialsException e){ + AuthResponse response = new AuthResponse(false, e.getMessage(), null); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); + } + } -- GitLab