perf(AuthController): devolver JSON en mensajes de error

parent 89e65cf0
......@@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.net.URI;
import java.util.Collections;
import java.util.stream.Collectors;
@RestController
......@@ -51,13 +52,15 @@ public class AuthController {
User user = readUserService.readByEmail(loginRequest.getEmail());
if (!passwordEncoder.matches(loginRequest.getPassword(), user.getPassword()))
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Contraseña incorrecta");
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
.body(Collections.singletonMap("message", "Contraseña incorrecta"));
String token = jwtTokenProvider.generateToken(user.getId());
return ResponseEntity.ok(new AuthResponse(token));
} catch (EntityNotFoundException e) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Usuario no encontrado");
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).
body(Collections.singletonMap("message", "Usuario no encontrado"));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment