Skip to content

Commit

Permalink
Add EntityNotFound for ingest tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
SaaldjorMike committed Aug 12, 2024
1 parent 4d23462 commit 70a7e6f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ func (n *Actions) Delete(viewName, actionName string) error {
}
}
if actionID == "" {
return fmt.Errorf("unable to find action")
return ActionNotFound(actionID)
}

var mutation struct {
Expand Down
8 changes: 8 additions & 0 deletions api/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
type EntityType string

const (
EntityTypeIngestToken EntityType = "ingest-token"
EntityTypeParser EntityType = "parser"
EntityTypeAction EntityType = "action"
EntityTypeAlert EntityType = "alert"
Expand Down Expand Up @@ -36,6 +37,13 @@ func (e EntityNotFound) Error() string {
return fmt.Sprintf("%s %q not found", e.entityType.String(), e.key)
}

func IngestTokenNotFound(name string) error {
return EntityNotFound{
entityType: EntityTypeIngestToken,
key: name,
}
}

func ParserNotFound(name string) error {
return EntityNotFound{
entityType: EntityTypeParser,
Expand Down
3 changes: 1 addition & 2 deletions api/ingest-tokens.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api

import (
"fmt"
graphql "github.com/cli/shurcooL-graphql"
)

Expand Down Expand Up @@ -61,7 +60,7 @@ func (i *IngestTokens) Get(repoName, tokenName string) (*IngestToken, error) {
}
}

return nil, fmt.Errorf("could not find an ingest token with name '%s' in repo '%s'", tokenName, repoName)
return nil, IngestTokenNotFound(tokenName)
}

func toIngestToken(data ingestTokenData) *IngestToken {
Expand Down

0 comments on commit 70a7e6f

Please sign in to comment.