From eafdd46e889a4b4a0cd2d1eaca2365095f4e3644 Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Mon, 12 Aug 2024 16:23:40 +0200 Subject: [PATCH] Add RepositoryNotFound and ViewNotFound responses to Get() calls --- api/error.go | 16 ++++++++++++++++ api/repositories.go | 3 +-- api/views.go | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/api/error.go b/api/error.go index 7432abb..1c249d1 100644 --- a/api/error.go +++ b/api/error.go @@ -7,6 +7,8 @@ import ( type EntityType string const ( + EntityTypeRepository EntityType = "repository" + EntityTypeView EntityType = "view" EntityTypeIngestToken EntityType = "ingest-token" EntityTypeParser EntityType = "parser" EntityTypeAction EntityType = "action" @@ -37,6 +39,20 @@ func (e EntityNotFound) Error() string { return fmt.Sprintf("%s %q not found", e.entityType.String(), e.key) } +func RepositoryNotFound(name string) error { + return EntityNotFound{ + entityType: EntityTypeRepository, + key: name, + } +} + +func ViewNotFound(name string) error { + return EntityNotFound{ + entityType: EntityTypeView, + key: name, + } +} + func IngestTokenNotFound(name string) error { return EntityNotFound{ entityType: EntityTypeIngestToken, diff --git a/api/repositories.go b/api/repositories.go index a37b70d..351bda3 100644 --- a/api/repositories.go +++ b/api/repositories.go @@ -38,8 +38,7 @@ func (r *Repositories) Get(name string) (Repository, error) { err := r.client.Query(&query, variables) if err != nil { - // The graphql error message is vague if the repo already exists, so add a hint. - return query.Repository, fmt.Errorf("%w. Does the repo already exist?", err) + return query.Repository, RepositoryNotFound(name) } return query.Repository, nil diff --git a/api/views.go b/api/views.go index 7f058b9..7f0dc73 100644 --- a/api/views.go +++ b/api/views.go @@ -48,7 +48,7 @@ func (c *Views) Get(name string) (*View, error) { err := c.client.Query(&query, variables) if err != nil { - return nil, err + return nil, ViewNotFound(name) } connections := make([]ViewConnection, len(query.Result.ViewInfo.Connections))