HTTPException interrupts the processing of a request and returns an HTTP error with a status code and a message, for example 404 if a resource does not exist. FastAPI converts it into a suitable JSON response, with the detail field.
Example
raise HTTPException(status_code=404, detail='Item not found')