Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize endpoint exception raising #985

Open
SteveMicroNova opened this issue Oct 16, 2024 · 1 comment
Open

Standardize endpoint exception raising #985

SteveMicroNova opened this issue Oct 16, 2024 · 1 comment
Labels
enhancement New feature or request support Improves our ability to support our platform webapp Web application development

Comments

@SteveMicroNova
Copy link
Contributor

SteveMicroNova commented Oct 16, 2024

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

@SteveMicroNova SteveMicroNova added enhancement New feature or request webapp Web application development support Improves our ability to support our platform labels Oct 16, 2024
@linknum23
Copy link
Contributor

The place to start looking at this is

def code_response(ctrl: Api, resp: Union[ApiResponse, models.BaseModel]):
. I'm sure there are a couple of more places, but almost all of the requests are funneled through there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request support Improves our ability to support our platform webapp Web application development
Projects
None yet
Development

No branches or pull requests

2 participants