refactor: use errors.Is()/errors.AsType() for error comparison and rename shadowed variables
Replace direct error equality checks (err == pgx.ErrNoRows, err != http.ErrServerClosed) with the idiomatic errors.Is() function throughout handlers, services, middleware, and app startup. This correctly handles wrapped error chains. Also replace a raw type assertion (*HTTPError) with errors.AsType[*HTTPError]() in the error handler middleware for consistency. Additionally, rename shadowed variables for clarity: - sidecar.go: config -> sidecarConfig, systemConfig (shadowed package-level vars) - media_scanner.go: uuid -> uuidString (shadowed the uuid package import)
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
wsync "bookhoard/internal/sync"
|
||||
"bookhoard/internal/utils"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -891,7 +892,7 @@ func (h *CollectionHandler) PreviewCollection(c *echo.Context) error {
|
||||
|
||||
_, err = h.db.GetLibrary(c.Request().Context(), pgtype.UUID{Bytes: libUUID, Valid: true})
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "library not found"})
|
||||
}
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
|
||||
Reference in New Issue
Block a user