Preserve owning categories in public errors
This commit is contained in:
25
errors.go
25
errors.go
@@ -17,6 +17,31 @@ func mapPublicError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
var operation *usecase.OperationError
|
||||
if errors.As(err, &operation) && operation != nil {
|
||||
owner := publicErrorFor(operation.Category)
|
||||
if owner != nil {
|
||||
// Project the underlying specialized error separately, retaining both
|
||||
// the outer operation and the original cause for Is/As callers.
|
||||
mapped := mapPublicError(operation.Cause)
|
||||
if errors.Is(operation.Cause, llm.ErrTransport) {
|
||||
mapped = errors.Join(ErrTransport, mapped)
|
||||
}
|
||||
if errors.Is(operation.Cause, llm.ErrMalformedResponse) {
|
||||
mapped = errors.Join(ErrMalformedResponse, mapped)
|
||||
}
|
||||
var internalCapacity *usecase.CapacityError
|
||||
var internalProvider *llm.ProviderHTTPError
|
||||
if errors.As(operation.Cause, &internalCapacity) || errors.As(operation.Cause, &internalProvider) {
|
||||
return errors.Join(owner, mapped)
|
||||
}
|
||||
return errors.Join(owner, mapped, operation.Cause)
|
||||
}
|
||||
}
|
||||
return mapUnownedPublicError(err)
|
||||
}
|
||||
|
||||
func mapUnownedPublicError(err error) error {
|
||||
var internalCapacityError *usecase.CapacityError
|
||||
if errors.As(err, &internalCapacityError) && internalCapacityError != nil &&
|
||||
strings.TrimSpace(internalCapacityError.BackendID) != "" {
|
||||
|
||||
Reference in New Issue
Block a user