xivind / velo-supervisor-2000

Program to monitor bicycle service intervals
2 stars 0 forks source link

Implement exception handling in endpoints #23

Open xivind opened 3 months ago

xivind commented 3 months ago

All endpoints must have try / except blocks

xivind commented 2 months ago

Partly fixed with code below, must be present in all endpoints. Does not catch 404 errors.. Maybe also something to catch errors that are caused when non-existent endpoints are called?

`except Exception as error:

Handle other exceptions does not catch 404

    if isinstance(error, HTTPException):
        # If the exception is an HTTPException, handle it accordingly
        if error.status_code == status.HTTP_503_SERVICE_UNAVAILABLE:
            # Handle 503 Service Unavailable error
            return render_error_page(request, error.status_code, str(error.detail))
        else:
            # Handle other HTTP errors
            return render_error_page(request, error.status_code, str(error.detail))
    else:
        # Handle other exceptions (e.g., internal server errors)
        return render_error_page(request, 500, str(error))`