Skip to content

Commit

Permalink
add docstring to errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Sep 26, 2024
1 parent 20dcce9 commit f4df9c1
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,25 @@ const (
)

var (
ErrTransactionNotFound = errors.New("no transaction found")
ErrContractNotFound = errors.New("no contract found")
// ErrTransactionNotFound is returned by /transactions/:id when we are
// unable to find the transaction with that `id`.
ErrTransactionNotFound = errors.New("no transaction found")
// ErrSiacoinOutputNotFound is returned by /outputs/siacoin/:id when we
// are unable to find the siacoin output with that `id`.
ErrSiacoinOutputNotFound = errors.New("no siacoin output found")
// ErrSiafundOutputNotFound is returned by /outputs/siafund/:id when we
// are unable to find the siafund output with that `id`.
ErrSiafundOutputNotFound = errors.New("no siafund output found")
ErrHostNotFound = errors.New("no host found")
// ErrHostNotFound is returned by /pubkey/:key/host when we are unable to
// find the host with the pubkey `key`.
ErrHostNotFound = errors.New("no host found")

ErrNoResults = errors.New("no search results found")
// ErrNoSearchResults is returned by /search/:id when we do not find any
// elements with that ID.
ErrNoSearchResults = errors.New("no search results found")

// ErrTooManyIDs is returned by the batch transaction and contract
// endpoints when more than maxIDs IDs are specified.
ErrTooManyIDs = fmt.Errorf("too many IDs provided (provide less than %d)", maxIDs)
)

Expand Down Expand Up @@ -427,7 +438,7 @@ func (s *server) contractsIDHandler(jc jape.Context) {
if jc.Check("failed to get contract", err) != nil {
return
} else if len(fcs) == 0 {
jc.Error(ErrContractNotFound, http.StatusNotFound)
jc.Error(explorer.ErrContractNotFound, http.StatusNotFound)
return
}
jc.Encode(fcs[0])
Expand All @@ -440,7 +451,7 @@ func (s *server) contractsIDRevisionsHandler(jc jape.Context) {
}

fcs, err := s.e.ContractRevisions(id)
if errors.Is(err, ErrContractNotFound) {
if errors.Is(err, explorer.ErrContractNotFound) {
jc.Error(fmt.Errorf("%w: %v", err, id), http.StatusNotFound)
return
} else if jc.Check("failed to fetch contract revisions", err) != nil {
Expand Down Expand Up @@ -474,7 +485,7 @@ func (s *server) pubkeyContractsHandler(jc jape.Context) {
if jc.Check("failed to get contracts", err) != nil {
return
} else if len(fcs) == 0 {
jc.Error(ErrContractNotFound, http.StatusNotFound)
jc.Error(explorer.ErrContractNotFound, http.StatusNotFound)
return
}
jc.Encode(fcs)
Expand Down Expand Up @@ -510,7 +521,7 @@ func (s *server) searchIDHandler(jc jape.Context) {
if jc.Check("failed to search ID", err) != nil {
return
} else if result == explorer.SearchTypeInvalid {
jc.Error(ErrNoResults, http.StatusNotFound)
jc.Error(ErrNoSearchResults, http.StatusNotFound)
return
}
jc.Encode(result)
Expand Down

0 comments on commit f4df9c1

Please sign in to comment.