File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
main-owner-service/api/src/main/java/com/main_owner_service/api/controllers Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 5
5
import com .main_owner_service .domain .models .LabeledOwner ;
6
6
import org .springframework .http .HttpStatus ;
7
7
import org .springframework .http .ResponseEntity ;
8
+ import org .springframework .http .converter .HttpMessageNotReadableException ;
9
+ import org .springframework .web .bind .annotation .ExceptionHandler ;
8
10
import org .springframework .web .bind .annotation .GetMapping ;
9
11
import org .springframework .web .bind .annotation .PathVariable ;
10
12
import org .springframework .web .bind .annotation .RestController ;
11
13
14
+ import static org .springframework .http .HttpStatus .BAD_REQUEST ;
15
+
12
16
@ RestController
13
17
public class FetchLabeledOwnerController {
14
18
@@ -21,6 +25,14 @@ public class FetchLabeledOwnerController {
21
25
@ GetMapping (value = "/fetch-labeled-owner/{id}" )
22
26
public ResponseEntity <String > fetchOwner (@ PathVariable ("id" ) Long ownerId ) {
23
27
LabeledOwner labeledOwner = fetchOwnerUseCase .fetchLabeledOwner (ownerId );
28
+ if (labeledOwner == null )
29
+ throw new IllegalArgumentException ("LabeledOwner not found" );
24
30
return new ResponseEntity <>(DataClassSerialization .serialize (labeledOwner ), HttpStatus .OK );
25
31
}
32
+
33
+ @ ExceptionHandler (IllegalArgumentException .class )
34
+ static ResponseEntity <String > handleMalformedBody (IllegalArgumentException exception ) {
35
+ return new ResponseEntity <>(exception .getMessage (), HttpStatus .BAD_REQUEST );
36
+ }
37
+
26
38
}
You can’t perform that action at this time.
0 commit comments