Add sentinel errors for HTTP status code handling#38
Add sentinel errors for HTTP status code handling#38alexellis merged 1 commit intoopenfaas:masterfrom
Conversation
Add ErrNotFound, ErrUnauthorized, ErrForbidden, and ErrUnexpectedStatus sentinel errors so callers can use errors.Is to distinguish error cases. - Add status code switches to GetNamespaces, GetFunctions, GetFunction, GetInfo, and GetSecrets which previously had no or partial checks - Update all existing methods to wrap sentinel errors consistently - Handle 403 Forbidden responses with ErrForbidden across all methods Breaking change: error messages returned by Client methods have changed. Code that matches on exact error strings will need to be updated. Use errors.Is with the new sentinel errors instead: errors.Is(err, sdk.ErrNotFound) errors.Is(err, sdk.ErrUnauthorized) errors.Is(err, sdk.ErrForbidden) errors.Is(err, sdk.ErrUnexpectedStatus) Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
AI Pull Request OverviewSummary
Approval rating (1-10)8 - Solid implementation with proper error handling improvements, but introduces breaking changes to error messages. Summary per fileSummary per file
Overall AssessmentThe changes significantly improve error handling consistency and reliability by introducing sentinel errors that enable proper error type checking with errors.Is. Methods that previously had incomplete status code validation now correctly handle 401, 403, 404, and unexpected status codes. The addition of 403 Forbidden handling is comprehensive. However, this is a breaking change as error messages have changed, requiring callers to update from string matching to errors.Is checks. The implementation appears correct and well-tested. Detailed ReviewDetailed Reviewclient.go
client_test.go
General Concerns
Recommendations
AI agent details. |
I'm trusting you've tested these with all callers and have found no regressions. |
Description
Add
ErrNotFound,ErrUnauthorized,ErrForbidden, andErrUnexpectedStatussentinel errors so callers can useerrors.Isto distinguish error cases returned by Client methods.GetNamespaces,GetFunctions,GetFunction,GetInfo, andGetSecretswhich previously had no or only partial status code checks403 Forbiddenresponses withErrForbiddenacross all methodsWe chose sentinel errors specifically to avoid diverging from the current method call signatures. Callers can use
errors.Iswithout any changes to return types:Breaking change: Error messages returned by Client methods have changed. Code that matches on exact error strings will need to be updated to use
errors.Iswith the new sentinel errors instead.Motivation and context
The OpenFaaS dashboard uses this SDK and needed to distinguish between different API error conditions—particularly authorization errors—to handle them differently for display in the UI. Without sentinel errors, callers had to resort to fragile string matching on error messages which made it difficult to reliably detect specific error conditions.
How has this been tested
errors.Iswith the new sentinel errors and new test cases for403 Forbiddenhave been added across all methods