refactor(handlers): use errors.Is() for pgx error comparison in KOReader
Replace direct equality checks (err != pgx.ErrNoRows) with the idiomatic errors.Is(err, pgx.ErrNoRows) pattern. This is the recommended Go practice for error comparison as it correctly handles wrapped errors from error chains, making the code more robust against future refactoring that might wrap errors with fmt.Errorf and %w.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"bookhoard/internal/database"
|
"bookhoard/internal/database"
|
||||||
wsync "bookhoard/internal/sync"
|
wsync "bookhoard/internal/sync"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@@ -401,11 +402,11 @@ func (h *KOReaderHandler) updateProgressForBook(c *echo.Context, userID pgtype.U
|
|||||||
UserID: userID,
|
UserID: userID,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil && err != pgx.ErrNoRows {
|
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
hasExistingProgress := err != pgx.ErrNoRows
|
hasExistingProgress := !errors.Is(err, pgx.ErrNoRows)
|
||||||
conflictDetected := false
|
conflictDetected := false
|
||||||
|
|
||||||
if hasExistingProgress && existingProgress.LastSyncSource.Valid {
|
if hasExistingProgress && existingProgress.LastSyncSource.Valid {
|
||||||
|
|||||||
Reference in New Issue
Block a user