Skip to content

Commit eafdd46

Browse files
committed
Add RepositoryNotFound and ViewNotFound responses to Get() calls
1 parent 70a7e6f commit eafdd46

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

api/error.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
type EntityType string
88

99
const (
10+
EntityTypeRepository EntityType = "repository"
11+
EntityTypeView EntityType = "view"
1012
EntityTypeIngestToken EntityType = "ingest-token"
1113
EntityTypeParser EntityType = "parser"
1214
EntityTypeAction EntityType = "action"
@@ -37,6 +39,20 @@ func (e EntityNotFound) Error() string {
3739
return fmt.Sprintf("%s %q not found", e.entityType.String(), e.key)
3840
}
3941

42+
func RepositoryNotFound(name string) error {
43+
return EntityNotFound{
44+
entityType: EntityTypeRepository,
45+
key: name,
46+
}
47+
}
48+
49+
func ViewNotFound(name string) error {
50+
return EntityNotFound{
51+
entityType: EntityTypeView,
52+
key: name,
53+
}
54+
}
55+
4056
func IngestTokenNotFound(name string) error {
4157
return EntityNotFound{
4258
entityType: EntityTypeIngestToken,

api/repositories.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ func (r *Repositories) Get(name string) (Repository, error) {
3838
err := r.client.Query(&query, variables)
3939

4040
if err != nil {
41-
// The graphql error message is vague if the repo already exists, so add a hint.
42-
return query.Repository, fmt.Errorf("%w. Does the repo already exist?", err)
41+
return query.Repository, RepositoryNotFound(name)
4342
}
4443

4544
return query.Repository, nil

api/views.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (c *Views) Get(name string) (*View, error) {
4848

4949
err := c.client.Query(&query, variables)
5050
if err != nil {
51-
return nil, err
51+
return nil, ViewNotFound(name)
5252
}
5353

5454
connections := make([]ViewConnection, len(query.Result.ViewInfo.Connections))

0 commit comments

Comments
 (0)