Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

418
Visualizações
FastAPI validation error on response_model

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 code and 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?

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda