Files
bifrost/core/providers/nebius/errors.go
Beyhan Oğur 880f412e2c first commit
2026-04-26 21:52:23 +03:00

65 lines
1.4 KiB
Go

package nebius
import (
"strings"
providerUtils "github.com/maximhq/bifrost/core/providers/utils"
"github.com/maximhq/bifrost/core/schemas"
"github.com/valyala/fasthttp"
)
// parseNebiusImageError parses Nebius error responses
func parseNebiusImageError(resp *fasthttp.Response) *schemas.BifrostError {
var nebiusErr NebiusError
bifrostErr := providerUtils.HandleProviderAPIError(resp, &nebiusErr)
if bifrostErr.Error == nil {
bifrostErr.Error = &schemas.ErrorField{}
}
// Extract error message
var message string
if nebiusErr.Detail != nil {
if nebiusErr.Detail.Message != nil {
message = *nebiusErr.Detail.Message
}
if len(nebiusErr.Detail.ValidationErrors) > 0 {
var messages []string
var locations []string
if message != "" {
messages = append(messages, message)
}
for _, detail := range nebiusErr.Detail.ValidationErrors {
if detail.Msg != "" {
messages = append(messages, detail.Msg)
}
if len(detail.Loc) > 0 {
locations = append(locations, strings.Join(detail.Loc, "."))
}
}
if len(messages) > 0 {
message = strings.Join(messages, "; ")
}
if len(locations) > 0 {
locationStr := strings.Join(locations, ", ")
if message == "" {
message = "[" + locationStr + "]"
} else {
message = message + " [" + locationStr + "]"
}
}
}
}
// Use the extracted message if available
if message != "" {
bifrostErr.Error.Message = message
}
return bifrostErr
}