diff --git a/server/forge/bitbucket/bitbucket.go b/server/forge/bitbucket/bitbucket.go index c1590fde7..d3c96920e 100644 --- a/server/forge/bitbucket/bitbucket.go +++ b/server/forge/bitbucket/bitbucket.go @@ -17,6 +17,7 @@ package bitbucket import ( "context" + "errors" "fmt" "net/http" "net/url" @@ -232,9 +233,15 @@ func (c *config) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error func (c *config) File(ctx context.Context, u *model.User, r *model.Repo, p *model.Pipeline, f string) ([]byte, error) { config, err := c.newClient(ctx, u).FindSource(r.Owner, r.Name, p.Commit, f) if err != nil { + var rspErr internal.Error + if ok := errors.As(err, &rspErr); ok && rspErr.Status == http.StatusNotFound { + return nil, &forge_types.ErrConfigNotFound{ + Configs: []string{f}, + } + } return nil, err } - return []byte(*config), err + return []byte(*config), nil } // Dir fetches a folder from the bitbucket repository @@ -245,6 +252,12 @@ func (c *config) Dir(ctx context.Context, u *model.User, r *model.Repo, p *model for { filesResp, err := client.GetRepoFiles(r.Owner, r.Name, p.Commit, f, page) if err != nil { + var rspErr internal.Error + if ok := errors.As(err, &rspErr); ok && rspErr.Status == http.StatusNotFound { + return nil, &forge_types.ErrConfigNotFound{ + Configs: []string{f}, + } + } return nil, err } for _, file := range filesResp.Values { diff --git a/server/forge/bitbucket/bitbucket_test.go b/server/forge/bitbucket/bitbucket_test.go index 0f3823e68..dd3842964 100644 --- a/server/forge/bitbucket/bitbucket_test.go +++ b/server/forge/bitbucket/bitbucket_test.go @@ -18,6 +18,7 @@ package bitbucket import ( "bytes" "context" + "errors" "net/http" "net/http/httptest" "testing" @@ -179,6 +180,7 @@ func Test_bitbucket(t *testing.T) { g.It("Should handle not found error", func() { _, err := c.File(ctx, fakeUser, fakeRepo, fakePipeline, "file_not_found") g.Assert(err).IsNotNil() + g.Assert(errors.Is(err, &types.ErrConfigNotFound{})).IsTrue() }) }) @@ -222,8 +224,9 @@ func Test_bitbucket(t *testing.T) { g.Assert(string(files[0].Data)).Equal("dummy payload") }) g.It("Should handle not found errors", func() { - _, err := c.Dir(ctx, fakeUser, fakeRepo, fakePipeline, "/dir_not_found") + _, err := c.Dir(ctx, fakeUser, fakeRepo, fakePipeline, "dir_not_found/") g.Assert(err).IsNotNil() + g.Assert(errors.Is(err, &types.ErrConfigNotFound{})).IsTrue() }) })