I have this endpoint in my API which calls another endpoint in another API. I'm just returning the received response to the client, but sometimes the client is actually receiving a different status_code
than the one I'm passing in the return
statement.
I'm doing it something like this (using FastAPI):
@router.post("/my_endpoint")
async def my_method():
...
response = requests.post(url=<url_to_the_other_api>, headers=headers, timeout=10)
return response.json()
The client is sometimes receiving an error message but still with status_code
200. I thought I was returning the same received response object, but apparently not.
May someone please explain it?
I thought json()
method or FastAPI could be creating a new response
object and just using the old body. Is that what happens? This behavior is quite unclear to me.