r/SpringBoot • u/dev-dp24 • Jan 10 '26
Question How should Exception Handling work between Spring MVC micro services and a Reactive API Gateway?
Hey everyone,
I am working on a microservice setup with five services: • api-gateway • entity • model • platform • user-management
All services are written using Spring MVC, except the API Gateway which is built using Spring WebFlux (reactive).
Right now, each backend microservice has its own custom exception handling. For example, the Platform service throws custom exceptions and returns a structured error response. Something like this:
Platform service error format
This works well when I call the Platform service directly. But when everything goes through the API Gateway, I do not want to expose this internal structure to the client.
On the API Gateway side, I want to catch these downstream custom exceptions and convert them into a simpler, more client friendly format.
Something like this:
API Gateway normal error format
So the flow I am aiming for is: 1. Platform service throws a custom exception and returns its detailed error JSON. 2. API Gateway receives that response using WebClient. 3. API Gateway extracts what it needs (status, errorCode, message). 4. API Gateway maps it to the normal gateway error format and sends that to the client.
My main questions are: • Is this a good design or am I overcomplicating it? • Should the API Gateway fully hide downstream error formats, or should it forward them as-is? • What is the cleanest way to implement this in Spring WebFlux?
If anyone has done something similar in a real production setup, I would love to hear how you handled it.
VERY IMPORTANT: I DO NOT WANT TO CREATE GLOBAL EXCEPTION HANDLER IN API GATEWAY.
Thanks in advance.
3
u/alfonsoristorato Jan 10 '26
I do not think what you would like to do is a bad design, in fact I think it's going to be quite a good impl and give you more visibility as a dev while not exposing unnecessary stuff to the client. When you say you do not want to create a global exception handler, I assume you mean you don't want a catch-all but a separated exception handler for each exception that gets thrown at some point by your other microservices, in which case I would agree that the logic should be separated by exception type. But at the same time, you will need a catch-all for any unexpected exception
2
u/BikingSquirrel Jan 10 '26
Why do your services return detailed error responses? Who's the audience?
It sounds like a lot of additional effort to transform them and keep the mapping updated - there needs to be a benefit to justify this.