1
1
package com .ganesh .security .controller ;
2
2
3
- import com .ganesh .security .exceptions .DuplicateEmailException ;
4
- import com .ganesh .security .exceptions .UserNotFoundException ;
5
3
import com .ganesh .security .payload .request .AuthenticationRequest ;
6
4
import com .ganesh .security .payload .request .RegisterRequest ;
7
5
import com .ganesh .security .payload .response .AuthenticationResponse ;
8
- import com .ganesh .security .payload .response .MessageResponse ;
9
6
import com .ganesh .security .service .AuthenticationService ;
10
7
import jakarta .servlet .http .HttpServletRequest ;
11
8
import jakarta .servlet .http .HttpServletResponse ;
12
9
import jakarta .validation .Valid ;
13
10
import lombok .RequiredArgsConstructor ;
14
- import org .springframework .http .HttpStatus ;
15
11
import org .springframework .http .ResponseEntity ;
16
- import org .springframework .validation .BindingResult ;
17
12
import org .springframework .web .bind .annotation .PostMapping ;
18
13
import org .springframework .web .bind .annotation .RequestBody ;
19
14
import org .springframework .web .bind .annotation .RequestMapping ;
@@ -30,38 +25,20 @@ public class AuthenticationController {
30
25
31
26
@ PostMapping ("/register" )
32
27
public ResponseEntity <?> register (
33
- @ Valid @ RequestBody RegisterRequest request ,
34
- BindingResult bindingResult
35
- ) {
36
- try {
37
- if (bindingResult .hasErrors ()) return service .handleValidationErrors (bindingResult );
38
- AuthenticationResponse response = service .register (request );
39
- return ResponseEntity .ok (response );
40
- } catch (DuplicateEmailException ex ) {
41
- return ResponseEntity .status (HttpStatus .BAD_REQUEST )
42
- .body (new MessageResponse (ex .getMessage ()));
43
- } catch (Exception ex ) {
44
- return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR )
45
- .body (new MessageResponse ("An error occurred on the server" ));
46
- }
28
+ @ Valid @ RequestBody RegisterRequest request
29
+ ) {
30
+ // if (bindingResult.hasErrors()) return service.handleValidationErrors(bindingResult);
31
+ AuthenticationResponse response = service .register (request );
32
+ return ResponseEntity .ok (response );
47
33
}
48
34
49
35
50
36
@ PostMapping ("/authenticate" )
51
37
public ResponseEntity <?> authenticate (
52
- @ Valid @ RequestBody AuthenticationRequest request ,
53
- BindingResult bindingResult
54
- ) {
55
- try {
56
- if (bindingResult .hasErrors ()) return service .handleValidationErrors (bindingResult );
57
- return ResponseEntity .ok (service .authenticate (request ));
58
- } catch (UserNotFoundException ex ) {
59
- return ResponseEntity .status (HttpStatus .BAD_REQUEST )
60
- .body (new MessageResponse (ex .getMessage ()));
61
- } catch (Exception ex ) {
62
- return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR )
63
- .body (new MessageResponse ("An error occurred on the server" ));
64
- }
38
+ @ Valid @ RequestBody AuthenticationRequest request
39
+ ) {
40
+ // if (bindingResult.hasErrors()) return service.handleValidationErrors(bindingResult);
41
+ return ResponseEntity .ok (service .authenticate (request ));
65
42
}
66
43
67
44
@ PostMapping ("/refresh-token" )
0 commit comments