File tree Expand file tree Collapse file tree 3 files changed +33
-4
lines changed
src/main/java/es/in2/vcverifier Expand file tree Collapse file tree 3 files changed +33
-4
lines changed Original file line number Diff line number Diff line change 1+ package es .in2 .vcverifier .exception ;
2+
3+ public class ResourceNotFoundException extends RuntimeException {
4+
5+ public ResourceNotFoundException (String message ) {
6+ super (message );
7+ }
8+
9+ }
Original file line number Diff line number Diff line change 1+ package es .in2 .vcverifier .exception .handler ;
2+
3+ import es .in2 .vcverifier .exception .ResourceNotFoundException ;
4+ import org .springframework .http .HttpStatus ;
5+ import org .springframework .http .ResponseEntity ;
6+ import org .springframework .web .bind .annotation .ControllerAdvice ;
7+ import org .springframework .web .bind .annotation .ExceptionHandler ;
8+
9+ @ ControllerAdvice
10+ public class CustomExceptionHandler {
11+
12+ @ ExceptionHandler (ResourceNotFoundException .class )
13+ public ResponseEntity <String > handleResourceNotFoundException (ResourceNotFoundException ex ) {
14+ return ResponseEntity .status (HttpStatus .NOT_FOUND ).body (ex .getMessage ());
15+ }
16+
17+ @ ExceptionHandler (Exception .class )
18+ public ResponseEntity <String > handleException (Exception ex ) {
19+ return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).body ("An unexpected error occurred: " + ex .getMessage ());
20+ }
21+ }
22+
Original file line number Diff line number Diff line change 11package es .in2 .vcverifier .oid4vp .controller ;
22
33import es .in2 .vcverifier .config .CacheStore ;
4+ import es .in2 .vcverifier .exception .ResourceNotFoundException ;
45import es .in2 .vcverifier .model .AuthorizationRequestJWT ;
56import es .in2 .vcverifier .oid4vp .service .AuthorizationResponseProcessorService ;
67import jakarta .servlet .http .HttpServletResponse ;
@@ -29,12 +30,9 @@ public ResponseEntity<String> getAuthorizationRequest(@PathVariable String id) {
2930 String jwt = authorizationRequestJWT .authRequest ();
3031
3132 if (jwt != null ) {
32- // Si el JWT existe en la caché, lo devolvemos en la respuesta
3333 return ResponseEntity .ok (jwt );
3434 } else {
35- // Si no se encuentra el JWT, devolvemos un error 404
36- return ResponseEntity .status (HttpStatus .NOT_FOUND )
37- .body ("JWT not found for id: " + id );
35+ throw new ResourceNotFoundException ("JWT not found for id: " + id );
3836 }
3937 }
4038
You can’t perform that action at this time.
0 commit comments