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) }