Skip to content

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

Open
@sam57719

Description

@sam57719

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions