Skip to content

Commit a140b43

Browse files
committed
Address code review comments
Signed-off-by: Priya Wadhwa <priya@chainguard.dev>
1 parent 69e6d64 commit a140b43

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/mediocregopher/radix/v4 v4.1.0
2626
github.com/mitchellh/go-homedir v1.1.0
2727
github.com/mitchellh/mapstructure v1.5.0
28-
github.com/pkg/errors v0.9.1
28+
github.com/pkg/errors v0.9.1 // indirect
2929
github.com/prometheus/client_golang v1.12.2
3030
github.com/rs/cors v1.8.2
3131
github.com/sassoftware/relic v0.0.0-20210427151427-dfb082b79b74

pkg/api/entries.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"bytes"
2020
"context"
2121
"encoding/hex"
22+
"errors"
2223
"fmt"
2324
"net/http"
2425
"net/url"
@@ -30,7 +31,6 @@ import (
3031
"github.com/go-openapi/swag"
3132
"github.com/google/trillian"
3233
ttypes "github.com/google/trillian/types"
33-
"github.com/pkg/errors"
3434
"github.com/spf13/viper"
3535
"github.com/transparency-dev/merkle/rfc6962"
3636
"golang.org/x/sync/errgroup"
@@ -313,7 +313,10 @@ func getEntryURL(locationURL url.URL, uuid string) strfmt.URI {
313313
func GetLogEntryByUUIDHandler(params entries.GetLogEntryByUUIDParams) middleware.Responder {
314314
logEntry, err := retrieveLogEntry(params.HTTPRequest.Context(), params.EntryUUID)
315315
if err != nil {
316-
return handleRekorAPIError(params, http.StatusNotFound, err, "ID %s not found in any known trees", params.EntryUUID)
316+
if _, ok := (err).(types.ValidationError); ok {
317+
return handleRekorAPIError(params, http.StatusBadRequest, err, "incorrectly formatted uuid %s", params.EntryUUID)
318+
}
319+
return handleRekorAPIError(params, http.StatusInternalServerError, err, "ID %s not found in any known trees", params.EntryUUID)
317320
}
318321
return entries.NewGetLogEntryByUUIDOK().WithPayload(logEntry)
319322
}
@@ -333,8 +336,7 @@ func SearchLogQueryHandler(params entries.SearchLogQueryParams) middleware.Respo
333336
if err != nil {
334337
return handleRekorAPIError(params, http.StatusBadRequest, err, fmt.Sprintf("could not get UUID from ID string %v", entryID))
335338
}
336-
logEntry, err := retrieveLogEntry(httpReqCtx, entryID)
337-
if err == nil {
339+
if logEntry, err := retrieveLogEntry(httpReqCtx, entryID); err == nil {
338340
resultPayload = append(resultPayload, logEntry)
339341
continue
340342
}
@@ -455,7 +457,7 @@ var ErrNotFound = errors.New("grpc returned 0 leaves with success code")
455457
func retrieveLogEntry(ctx context.Context, entryUUID string) (models.LogEntry, error) {
456458
uuid, err := sharding.GetUUIDFromIDString(entryUUID)
457459
if err != nil {
458-
return models.LogEntry{}, errors.Wrap(err, "getting uuid from id string")
460+
return models.LogEntry{}, sharding.ErrPlainUUID
459461
}
460462

461463
// Get the tree ID and check that shard for the entry
@@ -484,7 +486,7 @@ func retrieveLogEntry(ctx context.Context, entryUUID string) (models.LogEntry, e
484486
func retrieveUUIDFromTree(ctx context.Context, uuid string, tid int64) (models.LogEntry, error) {
485487
hashValue, err := hex.DecodeString(uuid)
486488
if err != nil {
487-
return models.LogEntry{}, err
489+
return models.LogEntry{}, types.ValidationError(err)
488490
}
489491

490492
tc := NewTrillianClientFromTreeID(ctx, tid)

0 commit comments

Comments
 (0)