Skip to content

Make SMIBHID sensor values return 404 rather than 500 for non-existant/uninitiated/invalid sensors/modules/readings #36

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

Open
sam57719 opened this issue Mar 15, 2025 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers invalid This doesn't seem right

Comments

@sam57719
Copy link
Collaborator

404 (NOT FOUND) is likely the correct status rather than 500 (INTERNAL SERVER ERROR)

looks like if you do the following a 404 error is returned correctly. I tested it with a broad try/except but the KeyError looks to be the exception that gets triggered.

from http.webserver import HTTPException
...
...
...
class Modules():

    def get(self, data, sensors, logger: uLogger) -> str:
        logger.info("API request - sensors/modules")
        try:
            html = dumps(sensors.get_modules())
            logger.info(f"Return value: {html}")
        except KeyError:
            raise HTTPException(404)
        return html

Originally posted by @sam57719 in somakeit/smib#276 (comment)

@sjefferson99 sjefferson99 transferred this issue from somakeit/smib Mar 31, 2025
@sjefferson99 sjefferson99 added enhancement New feature or request good first issue Good for newcomers invalid This doesn't seem right labels Mar 31, 2025
@sjefferson99 sjefferson99 removed their assignment Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants