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:
1 parent
a42f0e3899
commit
be5718de52
1 file changed
+3
-2
@@ -4,6 +4,7 @@ import (
|
||||
"bookhoard/internal/database"
|
||||
wsync "bookhoard/internal/sync"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -401,11 +402,11 @@ func (h *KOReaderHandler) updateProgressForBook(c *echo.Context, userID pgtype.U
|
||||
UserID: userID,
|
||||
})
|
||||
|
||||
if err != nil && err != pgx.ErrNoRows {
|
||||
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
|
||||
return err
|
||||
}
|
||||
|
||||
hasExistingProgress := err != pgx.ErrNoRows
|
||||
hasExistingProgress := !errors.Is(err, pgx.ErrNoRows)
|
||||
conflictDetected := false
|
||||
|
||||
if hasExistingProgress && existingProgress.LastSyncSource.Valid {
|
||||
|
||||
Reference in new issue
Block a user