8000 Handle lack of labeled owner in FetchLabeledOwnerController · PawelPacholek/java-gcp-pubsub@868e59a · GitHub
[go: up one dir, main page]

Skip to content

Commit 868e59a

Browse files
committed
Handle lack of labeled owner in FetchLabeledOwnerController
1 parent 9b4136c commit 868e59a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

main-owner-service/api/src/main/java/com/main_owner_service/api/controllers/FetchLabeledOwnerController.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
import com.main_owner_service.domain.models.LabeledOwner;
66
import org.springframework.http.HttpStatus;
77
import org.springframework.http.ResponseEntity;
8+
import org.springframework.http.converter.HttpMessageNotReadableException;
9+
import org.springframework.web.bind.annotation.ExceptionHandler;
810
import org.springframework.web.bind.annotation.GetMapping;
911
import org.springframework.web.bind.annotation.PathVariable;
1012
import org.springframework.web.bind.annotation.RestController;
1113

14+
import static org.springframework.http.HttpStatus.BAD_REQUEST;
15+
1216
@RestController
1317
public class FetchLabeledOwnerController {
1418

@@ -21,6 +25,14 @@ public class FetchLabeledOwnerController {
2125
@GetMapping(value = "/fetch-labeled-owner/{id}")
2226
public ResponseEntity<String> fetchOwner(@PathVariable("id") Long ownerId) {
2327
LabeledOwner labeledOwner = fetchOwnerUseCase.fetchLabeledOwner(ownerId);
28+
if (labeledOwner == null)
29+
throw new IllegalArgumentException("LabeledOwner not found");
2430
return new ResponseEntity<>(DataClassSerialization.serialize(labeledOwner), HttpStatus.OK);
2531
}
32+
33+
@ExceptionHandler(IllegalArgumentException.class)
34+
static ResponseEntity<String> handleMalformedBody(IllegalArgumentException exception) {
35+
return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST);
36+
}
37+
2638
}

0 commit comments

Comments
 (0)
0