January 2018
Intermediate to advanced
414 pages
10h 29m
English
We know how to handle generic exceptions, but if we need to respond to our business logic, how could we handle them?
Let's consider that we are requesting a customer that does not exist; so far, our UserService will return a null customer if asked for a customer that does not exist. Then, we just output a 404 NOT FOUND status code, and since it is our customer, we will not send a body. But let's handle this using a custom business exception.
First, we will create a new class named CustomerNotFoundException that will inherit from Exception:
package com.microservices.chapter3class CustomerNotFoundException(message: String) : Exception(message)
Then, we could modify our CustomerController code to throw this exception: ...
Read now
Unlock full access