January 2018
Intermediate to advanced
414 pages
10h 29m
English
The controller advice is a great tool, but sometimes, we may use it just like an equivalent to a GO-TO instruction. We lose control of our flow and we let something just happen outside of our main logic.
Controller advice should be used only to handle extraordinary circumstances and we could avoid it by adding our business logic when we need to answer errors.
For example, we could simply modify our controller method like this:
@GetMapping(value = "/customer/{id}")fun getCustomer(@PathVariable id: Int): ResponseEntity<Any> { val customer = customerService.getCustomer(id) return if (customer != null) ResponseEntity(customer, HttpStatus.OK) else ResponseEntity(ErrorResponse("Customer Not Found", "customer '$id' ...
Read now
Unlock full access