Skip to content

Commit 21baf68

Browse files
authored
Fix build status error check condition (#1315)
1 parent 39b8599 commit 21baf68

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

packages/api/internal/handlers/template_build_status.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"github.com/google/uuid"
1111

1212
"github.com/e2b-dev/infra/packages/api/internal/api"
13+
templatecache "github.com/e2b-dev/infra/packages/api/internal/cache/templates"
1314
"github.com/e2b-dev/infra/packages/api/internal/utils"
1415
"github.com/e2b-dev/infra/packages/db/types"
15-
"github.com/e2b-dev/infra/packages/shared/pkg/db"
1616
"github.com/e2b-dev/infra/packages/shared/pkg/logs"
1717
"github.com/e2b-dev/infra/packages/shared/pkg/models/envbuild"
1818
"github.com/e2b-dev/infra/packages/shared/pkg/telemetry"
@@ -32,7 +32,8 @@ func (a *APIStore) GetTemplatesTemplateIDBuildsBuildIDStatus(c *gin.Context, tem
3232

3333
buildInfo, err := a.templateBuildsCache.Get(ctx, buildUUID, templateID)
3434
if err != nil {
35-
if errors.Is(err, db.TemplateBuildNotFoundError{}) {
35+
var notFoundErr templatecache.TemplateBuildInfoNotFoundError
36+
if errors.As(err, &notFoundErr) {
3637
a.sendAPIStoreError(c, http.StatusBadRequest, fmt.Sprintf("Build '%s' not found", buildUUID))
3738
return
3839
}

packages/shared/pkg/db/errors.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ func (TemplateBuildNotFoundError) Error() string {
88
return "Template build not found"
99
}
1010

11-
type SnapshotNotFoundError struct{ NotFoundError }
12-
13-
func (SnapshotNotFoundError) Error() string {
14-
return "Snapshot not found"
15-
}
16-
17-
type BuildNotFoundError struct{ NotFoundError }
18-
19-
func (BuildNotFoundError) Error() string {
20-
return "Build not found"
21-
}
22-
2311
type EnvNotFoundError struct{ NotFoundError }
2412

2513
func (EnvNotFoundError) Error() string {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package api_templates
2+
3+
import (
4+
"net/http"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/e2b-dev/infra/tests/integration/internal/setup"
10+
)
11+
12+
func TestInvalidBuildStatus(t *testing.T) {
13+
c := setup.GetAPIClient()
14+
15+
resp, err := c.GetTemplatesTemplateIDBuildsBuildIDStatusWithResponse(
16+
t.Context(),
17+
"non-existing",
18+
"also-non-existing",
19+
nil,
20+
setup.WithAccessToken(),
21+
)
22+
require.NoError(t, err)
23+
require.Equal(t, http.StatusBadRequest, resp.StatusCode())
24+
}

0 commit comments

Comments
 (0)