chore: cleanup handler
This commit is contained in:
parent
e9b7f7ab4b
commit
324a5b31e0
1 changed files with 5 additions and 4 deletions
|
@ -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) {
|
func (h *handler) RedirectLongURL(ctx context.Context, params oas.RedirectLongURLParams) (oas.RedirectLongURLRes, error) {
|
||||||
res, err := h.queries.GetURLByHash(ctx, params.Hash)
|
res, err := h.queries.GetURLByHash(ctx, params.Hash)
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, pgx.ErrNoRows) {
|
switch {
|
||||||
|
case errors.Is(err, pgx.ErrNoRows):
|
||||||
return &oas.RedirectLongURLNotFound{}, nil
|
return &oas.RedirectLongURLNotFound{}, nil
|
||||||
}
|
case err != nil:
|
||||||
return nil, fmt.Errorf("unable to fetch URL by hash: %w", err)
|
return nil, fmt.Errorf("unable to fetch URL by hash: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue