micro-nova / AmpliPi

Whole House Audio System 🔊
https://amplipi.com
GNU General Public License v3.0
288 stars 23 forks source link

Standardize endpoint exception raising #985

Open SteveMicroNova opened 3 weeks ago

SteveMicroNova commented 3 weeks ago

In our in-house inventory manager, I raise all errors with a custom error object. Here's what that looks like:

except Exception as e:
    raise HTTPException(
        status_code=422,
        detail = {
            "message":  note, // Here's  what is shown to the user or printed in the frontend console
            "error": e  // This is what's consumed by the fetch request to identify the specific error
    })

This specialized exception detail is consumable by things such as the components in the StatusBars folder no problem to preserve the error, but also share a user-understandable reason why something went wrong and sometimes even directions for how to fix it. We can't do everything the same way in AmpliPi, our users don't sit 15 feet behind me to tell me when something goes wrong, but there is something to be gained by this in support of #326

linknum23 commented 3 weeks ago

The place to start looking at this is https://github.com/micro-nova/AmpliPi/blob/7cc2f2a4472a194323f41b0d31b63e153f872871/amplipi/app.py#L296. I'm sure there are a couple of more places, but almost all of the requests are funneled through there.