Skip to content

Commit

Permalink
use grpc error codes (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamneal authored Aug 25, 2021
1 parent 7cf27b0 commit 8ab7abd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions generator/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,10 +934,12 @@ func WriteIters(p *Printer, s *Service) (outErr error) {
_, hasSecond := this.Next()
if !hasFirst || hasSecond {
amount := "none"
statusCode := codes.NotFound
if hasSecond {
amount = "multiple"
statusCode = codes.FailedPrecondition
}
return &Row_`, sName, `_`, camelQ(q), `{err: lib.NotFound{Msg: fmt.Sprintf("expected exactly 1 result from query '`, camelQ(q), `' found %s", amount)}}
return &Row_`, sName, `_`, camelQ(q), `{err: gstatus.Errorf(statusCode, "expected exactly 1 result from query '`, camelQ(q), `' found %s", amount)}
}
return first
}
Expand Down Expand Up @@ -1154,10 +1156,12 @@ func WriteIters(p *Printer, s *Service) (outErr error) {
_, hasSecond := this.Next()
if !hasFirst || hasSecond {
amount := "none"
statusCode := codes.NotFound
if hasSecond {
amount = "multiple"
statusCode = codes.FailedPrecondition
}
return &Row_`, sName, `_`, camelQ(q), `{err: fmt.Errorf("expected exactly 1 result from query '`, camelQ(q), `' found %s", amount)}
return &Row_`, sName, `_`, camelQ(q), `{err: gstatus.Errorf(statusCode, "expected exactly 1 result from query '`, camelQ(q), `' found %s", amount)}
}
return first
}
Expand Down

0 comments on commit 8ab7abd

Please sign in to comment.