Skip to content

Commit 04ba19b

Browse files
authored
Return correct status code for non existing sandbox in orchestrator in keep alive (#1405)
1 parent 00895b1 commit 04ba19b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/api/internal/orchestrator/keep_alive.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func (o *Orchestrator) KeepAliveFor(ctx context.Context, sandboxID string, durat
6161
}
6262
err = o.UpdateSandbox(ctx, sandboxID, sbx.EndTime, sbx.ClusterID, sbx.NodeID)
6363
if err != nil {
64+
if errors.Is(err, ErrSandboxNotFound) {
65+
return &api.APIError{Code: http.StatusNotFound, ClientMsg: "Sandbox not found", Err: err}
66+
}
67+
6468
return &api.APIError{Code: http.StatusInternalServerError, ClientMsg: "Error when setting sandbox timeout", Err: err}
6569
}
6670

packages/api/internal/orchestrator/update_instance.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/google/uuid"
1010
"go.opentelemetry.io/otel/attribute"
1111
"go.opentelemetry.io/otel/trace"
12+
"google.golang.org/grpc/codes"
13+
"google.golang.org/grpc/status"
1214
"google.golang.org/protobuf/types/known/timestamppb"
1315

1416
"github.com/e2b-dev/infra/packages/api/internal/utils"
@@ -41,9 +43,14 @@ func (o *Orchestrator) UpdateSandbox(
4143
EndTime: timestamppb.New(endTime),
4244
},
4345
)
44-
45-
err = utils.UnwrapGRPCError(err)
4646
if err != nil {
47+
grpcErr, ok := status.FromError(err)
48+
if ok && grpcErr.Code() == codes.NotFound {
49+
return ErrSandboxNotFound
50+
}
51+
52+
err = utils.UnwrapGRPCError(err)
53+
4754
return fmt.Errorf("failed to update sandbox '%s': %w", sandboxID, err)
4855
}
4956

0 commit comments

Comments
 (0)