diff --git a/api/server.go b/api/server.go index 0ddfd9a4..d72ba1f0 100644 --- a/api/server.go +++ b/api/server.go @@ -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) ) @@ -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]) @@ -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 { @@ -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) @@ -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)