first commit
This commit is contained in:
29
core/providers/replicate/errors.go
Normal file
29
core/providers/replicate/errors.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package replicate
|
||||
|
||||
import (
|
||||
"github.com/bytedance/sonic"
|
||||
schemas "github.com/maximhq/bifrost/core/schemas"
|
||||
)
|
||||
|
||||
// parseReplicateError parses Replicate API error response
|
||||
func parseReplicateError(body []byte, statusCode int) *schemas.BifrostError {
|
||||
var replicateErr ReplicateError
|
||||
if err := sonic.Unmarshal(body, &replicateErr); err == nil && replicateErr.Detail != "" {
|
||||
return &schemas.BifrostError{
|
||||
IsBifrostError: false,
|
||||
StatusCode: &statusCode,
|
||||
Error: &schemas.ErrorField{
|
||||
Message: replicateErr.Detail,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to generic error
|
||||
return &schemas.BifrostError{
|
||||
IsBifrostError: false,
|
||||
StatusCode: &statusCode,
|
||||
Error: &schemas.ErrorField{
|
||||
Message: string(body),
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user