Skip to content

Commit 7730b15

Browse files
committed
Refactor error handling to replace ResourceNotFoundException with NotFoundException
1 parent 61e4d79 commit 7730b15

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

solver-common/src/main/java/com/solver/GlobalExceptionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
public class GlobalExceptionHandler {
1313
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
1414

15-
@ExceptionHandler(ResourceNotFoundException.class)
16-
public ResponseEntity<String> handleResourceNotFoundException(ResourceNotFoundException e) {
15+
@ExceptionHandler(NotFoundException.class)
16+
public ResponseEntity<String> handleResourceNotFoundException(NotFoundException e) {
1717
logger.info("Resource not found: {}", e.getMessage());
1818
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
1919
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.solver;
2+
3+
public class NotFoundException extends RuntimeException {
4+
public NotFoundException(String message) {
5+
super(message);
6+
}
7+
8+
public NotFoundException(String message, Throwable cause) {
9+
super(message, cause);
10+
}
11+
}

solver-common/src/main/java/com/solver/ResourceNotFoundException.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

solver-common/src/main/java/com/solver/SolverController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public CompletableFuture<ResponseEntity<String>> getUserSettings(@PathVariable("
6666
return dbService.getUserSettings(userId)
6767
.thenApply(optionalSettings -> optionalSettings
6868
.map(ResponseEntity::ok)
69-
.orElseThrow(() -> new ResourceNotFoundException("User settings not found for userId: " + userId)));
69+
.orElseThrow(() -> new NotFoundException("User settings not found for userId: " + userId)));
7070
}
7171

7272
@GetMapping("/users/{userId}/applications")
@@ -75,7 +75,7 @@ public CompletableFuture<ResponseEntity<List<Map<String, Object>>>> getApplicati
7575
return dbService.getApplications(userId)
7676
.thenApply(applications -> {
7777
if (applications.isEmpty()) {
78-
throw new ResourceNotFoundException("Applications not found for userId: " + userId);
78+
throw new NotFoundException("Applications not found for userId: " + userId);
7979
}
8080
return ResponseEntity.ok(applications);
8181
});
@@ -86,27 +86,27 @@ public CompletableFuture<ResponseEntity<String>> getApplicationStatus(@PathVaria
8686
logger.debug("Getting application status for id: {}", applicationId);
8787

8888
if (applicationId <= 0) {
89-
throw new ResourceNotFoundException("Invalid applicationId: " + applicationId);
89+
throw new NotFoundException("Invalid applicationId: " + applicationId);
9090
}
9191

9292
return dbService.getApplicationStatus(applicationId)
9393
.thenApply(optionalStatus -> optionalStatus
9494
.map(ResponseEntity::ok)
95-
.orElseThrow(() -> new ResourceNotFoundException("Application not found for applicationId: " + applicationId)));
95+
.orElseThrow(() -> new NotFoundException("Application not found for applicationId: " + applicationId)));
9696
}
9797

9898
@GetMapping("/applications/{applicationId}/results")
9999
public CompletableFuture<ResponseEntity<List<Map<String, Object>>>> getResults(@PathVariable("applicationId") int applicationId) {
100100
logger.debug("Getting results for applicationId: {}", applicationId);
101101

102102
if (applicationId <= 0) {
103-
throw new ResourceNotFoundException("Invalid applicationId: " + applicationId);
103+
throw new NotFoundException("Invalid applicationId: " + applicationId);
104104
}
105105

106106
return dbService.getResults(applicationId)
107107
.thenApply(results -> {
108108
if (results.isEmpty()) {
109-
throw new ResourceNotFoundException("Results not found for applicationId: " + applicationId);
109+
throw new NotFoundException("Results not found for applicationId: " + applicationId);
110110
}
111111
return ResponseEntity.ok(results);
112112
});

0 commit comments

Comments
 (0)