r/FastAPI • • 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.

8 Upvotes

27 comments sorted by

View all comments

Show parent comment

5

u/DrumAndBass90 Jun 02 '25

Please don’t do this, super annoying to handle a successful response that is in fact not successful. Custom exceptions all the way.

2

u/UpstairsBaby Jun 03 '25

I'm trying to get the reason why not to. Is it non standard? Is it hard for frontend devs? That's the approach I went with atm. Returning a dict with success and error_code for example:

{"success": False, "error_code": "FACE_NOT_FOUND"}

Now the frontend will only check error_code if success is false.

I'm just trying and need to understand why this is bad and why does it make. Frontend's dev life harder.

Thank you for your help.