From 324a5b31e090e474e4a489025a5afa9c4b1d85cd Mon Sep 17 00:00:00 2001 From: Bastien Riviere Date: Fri, 9 Feb 2024 19:36:05 +0100 Subject: [PATCH] chore: cleanup handler --- internal/api/handler.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/api/handler.go b/internal/api/handler.go index 0911afc..b61d657 100644 --- a/internal/api/handler.go +++ b/internal/api/handler.go @@ -27,10 +27,11 @@ func NewHandler(serverUrl string, queries *db.Queries) *handler { func (h *handler) RedirectLongURL(ctx context.Context, params oas.RedirectLongURLParams) (oas.RedirectLongURLRes, error) { res, err := h.queries.GetURLByHash(ctx, params.Hash) - if err != nil { - if errors.Is(err, pgx.ErrNoRows) { - return &oas.RedirectLongURLNotFound{}, nil - } + + switch { + case errors.Is(err, pgx.ErrNoRows): + return &oas.RedirectLongURLNotFound{}, nil + case err != nil: return nil, fmt.Errorf("unable to fetch URL by hash: %w", err) }