Mam taki przypadek, ktory chcialbym zapisac uzywajac vavr'owego Try:
@GetMapping
public ResponseEntity<?> getSomething(@RequestParam(value = "param") String param) {
try {
return ResponseEntity.ok(service.getSomething(param));
} catch (IllegalArgumentException exception) {
return new ResponseEntity<>(new ErrorInfo("Param=" + param + " is not valid"), HttpStatus.BAD_REQUEST);
}
}
Probuje to zapisac w ten sposob, ale wtedy nie zgadza mi sie zwracany typ, bo getSomething zwraca jakis inny obiekt niz ErrorInfo
:
@GetMapping
public ResponseEntity<?> getSomething(@RequestParam(value = "param") String param) {
return Try.of(() -> service.getSomething(param))
.map(ResponseEntity::ok)
.recover(IllegalArgumentException.class, new ResponseEntity<>(new ErrorInfo("Param=" + param + " is not valid"), HttpStatus.BAD_REQUEST)
.get();
}
Da sie to w ogole ograc w Vavr?