Skip to content

Commit

Permalink
fix(api)!: retrieve on unexisting ressource should not return an error
Browse files Browse the repository at this point in the history
By returning errors, it drastically increased the error rate in OTEL spans/Jaeger monitoring which is semantically invalid: there was no service failure/downgrade, only a check to know if an API object existed or not.
  • Loading branch information
pandatix committed Nov 28, 2024
1 parent c525543 commit 2f62b6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/v1/challenge/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (store *Store) RetrieveChallenge(ctx context.Context, req *RetrieveChalleng
// 4. Fetch challenge info
fschall, err := fs.LoadChallenge(req.Id)
if err != nil {
// If challenge not found, is not an error
if _, ok := err.(*errs.ErrChallengeExist); ok {
return nil, nil
}
if err, ok := err.(*errs.ErrInternal); ok {
logger.Error(ctx, "loading challenge",
zap.Error(err),
Expand Down
4 changes: 4 additions & 0 deletions api/v1/instance/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ func (man *Manager) RetrieveInstance(ctx context.Context, req *RetrieveInstanceR
// 6. If instance does not exist, return error
fsist, err := fs.LoadInstance(req.ChallengeId, req.SourceId)
if err != nil {
// If instance not found, is not an error
if _, ok := err.(*errs.ErrInstanceExist); ok {
return nil, nil
}
if err, ok := err.(*errs.ErrInternal); ok {
logger.Error(ctx, "loading challenge instance",
zap.Error(err),
Expand Down

0 comments on commit 2f62b6a

Please sign in to comment.