Skip to content

Commit cb5320a

Browse files
committed
update llamastack Not Found error wrapping
1 parent 2b616f4 commit cb5320a

3 files changed

Lines changed: 15 additions & 16 deletions

File tree

packages/gen-ai/bff/internal/api/lsd_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (app *App) getDefaultStatusCodeForLlamaStackClientError(errorCode string) i
3232
return http.StatusBadRequest
3333
case llamastack.ErrCodeUnauthorized:
3434
return http.StatusUnauthorized
35-
case llamastack.ErrCodeModelNotFound:
35+
case llamastack.ErrCodeNotFound:
3636
return http.StatusNotFound
3737
case llamastack.ErrCodeConnectionFailed, llamastack.ErrCodeTimeout, llamastack.ErrCodeServerUnavailable:
3838
return http.StatusServiceUnavailable

packages/gen-ai/bff/internal/api/lsd_helpers_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func TestHandleLlamaStackClientError(t *testing.T) {
3838
expectedBodyContains: "unauthorized",
3939
},
4040
{
41-
name: "LlamaStackError with ModelNotFound code",
42-
inputError: llamastack.NewModelNotFoundError("gpt-4"),
41+
name: "LlamaStackError with NotFound code",
42+
inputError: llamastack.NewNotFoundError("resource not found"),
4343
expectedStatusCode: http.StatusNotFound,
4444
expectedBodyContains: "not_found",
4545
},
@@ -94,8 +94,8 @@ func TestGetDefaultStatusCodeForLlamaStackClientError(t *testing.T) {
9494
expectedStatusCode: http.StatusUnauthorized,
9595
},
9696
{
97-
name: "ModelNotFound code returns 404",
98-
errorCode: llamastack.ErrCodeModelNotFound,
97+
name: "NotFound code returns 404",
98+
errorCode: llamastack.ErrCodeNotFound,
9999
expectedStatusCode: http.StatusNotFound,
100100
},
101101
{
@@ -165,11 +165,11 @@ func TestMapLlamaStackClientErrorToHTTPError(t *testing.T) {
165165
},
166166
{
167167
name: "not found error",
168-
lsErr: llamastack.NewModelNotFoundError("gpt-4"),
168+
lsErr: llamastack.NewNotFoundError("resource not found"),
169169
statusCode: http.StatusNotFound,
170170
expectedCode: "not_found",
171171
expectedStatusCode: http.StatusNotFound,
172-
expectedMessage: "model 'gpt-4' not found or is not available",
172+
expectedMessage: "resource not found",
173173
},
174174
{
175175
name: "service unavailable error",
@@ -236,17 +236,17 @@ func TestLlamaStackHelpersIntegration(t *testing.T) {
236236
assert.Contains(t, rr.Body.String(), "input is required")
237237
})
238238

239-
t.Run("should handle LlamaStackError with model not found", func(t *testing.T) {
239+
t.Run("should handle LlamaStackError with not found", func(t *testing.T) {
240240
req := httptest.NewRequest("GET", "/test", nil)
241241
rr := httptest.NewRecorder()
242242

243-
lsErr := llamastack.NewModelNotFoundError("gpt-4")
243+
lsErr := llamastack.NewNotFoundError("resource not found")
244244

245245
app.handleLlamaStackClientError(rr, req, lsErr)
246246

247247
assert.Equal(t, http.StatusNotFound, rr.Code)
248248
assert.Contains(t, rr.Body.String(), `"code": "not_found"`)
249-
assert.Contains(t, rr.Body.String(), "gpt-4")
249+
assert.Contains(t, rr.Body.String(), "resource not found")
250250
})
251251

252252
t.Run("should fall back to serverErrorResponse for unknown error type", func(t *testing.T) {

packages/gen-ai/bff/internal/integrations/llamastack/errors.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const (
3333
ErrCodeServerUnavailable = "SERVER_UNAVAILABLE"
3434
ErrCodeUnauthorized = "UNAUTHORIZED"
3535
ErrCodeInvalidRequest = "INVALID_REQUEST"
36-
ErrCodeModelNotFound = "MODEL_NOT_FOUND"
36+
ErrCodeNotFound = "NOT_FOUND"
3737
ErrCodeInternalError = "INTERNAL_ERROR"
3838
)
3939

@@ -86,9 +86,9 @@ func NewInvalidRequestError(message string) *LlamaStackError {
8686
return NewLlamaStackError(ErrCodeInvalidRequest, message, 400)
8787
}
8888

89-
// NewModelNotFoundError creates a model not found error
90-
func NewModelNotFoundError(modelName string) *LlamaStackError {
91-
return NewLlamaStackError(ErrCodeModelNotFound, fmt.Sprintf("model '%s' not found or is not available", modelName), 404)
89+
// NewNotFoundError creates a not found error
90+
func NewNotFoundError(message string) *LlamaStackError {
91+
return NewLlamaStackError(ErrCodeNotFound, message, 404)
9292
}
9393

9494
// wrapClientError wraps errors from the llamastack OpenAI client into our LlamaStackError type for consistent error handling.
@@ -116,7 +116,6 @@ func wrapClientError(err error, operation string, metadata ...interface{}) error
116116
// Check for network-level errors (connection refused, timeout, DNS failures, etc.)
117117
var urlErr *url.Error
118118
if errors.As(err, &urlErr) {
119-
fmt.Printf("DEBUG wrapClientError: detected *url.Error\n")
120119
message := fmt.Sprintf("failed to connect to LlamaStack server while %s: %s", operation, urlErr.Err.Error())
121120
lsErr := NewConnectionError("LlamaStack server", message)
122121
lsErr.Metadata = meta
@@ -137,7 +136,7 @@ func wrapClientError(err error, operation string, metadata ...interface{}) error
137136
case http.StatusUnauthorized:
138137
lsErr = NewUnauthorizedError(message)
139138
case http.StatusNotFound:
140-
lsErr = NewModelNotFoundError(message)
139+
lsErr = NewNotFoundError(message)
141140
case http.StatusServiceUnavailable, http.StatusGatewayTimeout, http.StatusRequestTimeout:
142141
lsErr = NewServerUnavailableError(message)
143142
default:

0 commit comments

Comments
 (0)