I have an FastAPI server that communicates with another API server (Lumen) to retrieve data, basically it only proxies the routes to the Lumen server.
Inside Lumen routes we have some validation rules and when we pass invalid body request it fails and returns
422 error code and a message.
The problem is that my Fast API endpoint returns a
response_model for the request in particular, so when a validation error occurs it tries to return the response model and the server fails because the
message fields doesn't exist in our response_model
@router.post("/products/offers", response_model=OfferSearchResult, operation_id="offer_search") async def offer_search( body: OfferSearchRequest, context: AppContext = Depends(get_context), max_per_product: Optional[conint(ge=1, le=100)] = Query(None, alias="maxPerProduct"), sort_by: Optional[OfferSort] = Query(None, alias="sortBy"), ) -> OfferSearchResult: offer_search_result = await OfferService(context).get_offers(body, max_per_product=max_per_product, sort_by=sort_by) return offer_search_result
I tried to solve this by overriding
validation_exception_handler but didn't work, how can I return that Lumen's validation error message to return as a fastAPI response?