first commit
This commit is contained in:
38
core/providers/runway/errors.go
Normal file
38
core/providers/runway/errors.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package runway
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
providerUtils "github.com/maximhq/bifrost/core/providers/utils"
|
||||
schemas "github.com/maximhq/bifrost/core/schemas"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// parseRunwayError parses Runway API error responses and converts them to BifrostError.
|
||||
func parseRunwayError(resp *fasthttp.Response) *schemas.BifrostError {
|
||||
// Parse as RunwayAPIError
|
||||
var errorResp RunwayAPIError
|
||||
bifrostErr := providerUtils.HandleProviderAPIError(resp, &errorResp)
|
||||
|
||||
// Set error message if available
|
||||
if errorResp.Error != "" {
|
||||
if bifrostErr.Error == nil {
|
||||
bifrostErr.Error = &schemas.ErrorField{}
|
||||
}
|
||||
bifrostErr.Error.Message = errorResp.Error
|
||||
} else if bifrostErr.Error != nil && bifrostErr.Error.Message == "" {
|
||||
// If no error message was extracted, use a generic one
|
||||
bifrostErr.Error.Message = "Runway API request failed"
|
||||
} else if bifrostErr.Error == nil {
|
||||
bifrostErr.Error = &schemas.ErrorField{
|
||||
Message: "Runway API request failed",
|
||||
}
|
||||
}
|
||||
|
||||
// Remove trailing newlines
|
||||
if bifrostErr.Error != nil && bifrostErr.Error.Message != "" {
|
||||
bifrostErr.Error.Message = strings.TrimRight(bifrostErr.Error.Message, "\n")
|
||||
}
|
||||
|
||||
return bifrostErr
|
||||
}
|
||||
Reference in New Issue
Block a user