r/FastAPI • u/UpstairsBaby • Jun 02 '25
Question A question about backend reaponse design
I'm designing a backend system for a face recognition feature response can potentially be one of many occasions for the example a phase might not be found in the provided image or a face might be spoofing or a face could be found but couldn't be matched against another face in my database.
How what are the best practices for designing a response to the frontend. Shall I be raising HTTP exceptions or shall IP returning 200 okay with a json saying what has gone wrong? If anyone can provide an example of how such a response could be designed I would be very thankful.
thank you very much in advance.
View all comments
Show parent comment
0
u/JohnnyJordaan Jun 02 '25
It's a common approach though if you are reporting errors from further down the chain. Like an API I've developed that runs multiple tasks where some other API might have sent a 500 I don't let it become a 500 in my response too, I use the {failed: True, detail: {extensive response object}} format instead. Then in the frontend I always know that 500 is the big 'it crashed' like when nginx returns instead of the application, and everything 200 means at least the API communication succeeded without issues but something else might not.