diff --git a/v1/providers/nebius/errors.go b/v1/providers/nebius/errors.go index fd4b311d..49a87d80 100644 --- a/v1/providers/nebius/errors.go +++ b/v1/providers/nebius/errors.go @@ -3,6 +3,7 @@ package v1 import ( "fmt" + v1 "github.com/brevdev/cloud/v1" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -30,6 +31,20 @@ func isNotFoundError(err error) bool { return false } +func handleErrToCloudErr(e error) error { + if e == nil { + return nil + } + + // Check for gRPC ResourceExhausted status code + if grpcStatus, ok := status.FromError(e); ok { + if grpcStatus.Code() == codes.ResourceExhausted { + return v1.ErrOutOfQuota + } + } + return e +} + // isAlreadyExistsError checks if an error is an "already exists" error // //nolint:unused // Reserved for future error handling improvements diff --git a/v1/providers/nebius/instance.go b/v1/providers/nebius/instance.go index 3460efdb..40c569ee 100644 --- a/v1/providers/nebius/instance.go +++ b/v1/providers/nebius/instance.go @@ -143,17 +143,18 @@ func (c *NebiusClient) CreateInstance(ctx context.Context, attrs v1.CreateInstan operation, err := c.sdk.Services().Compute().V1().Instance().Create(ctx, createReq) if err != nil { - return nil, errors.WrapAndTrace(err) + return nil, errors.WrapAndTrace(handleErrToCloudErr(err)) } // Wait for the operation to complete and get the actual instance ID finalOp, err := operation.Wait(ctx) if err != nil { - return nil, errors.WrapAndTrace(err) + return nil, errors.WrapAndTrace(handleErrToCloudErr(err)) } if !finalOp.Successful() { - return nil, fmt.Errorf("instance creation failed: %v", finalOp.Status()) + statusErr := fmt.Errorf("instance creation failed: %v", finalOp.Status()) + return nil, handleErrToCloudErr(statusErr) } // Get the actual instance ID from the completed operation