fix: use sentinel ErrLocationNotFound to satisfy errorlint
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Replace errors.New("location not found") string with a package-level
sentinel var so callers can use errors.Is() instead of string comparison,
which errorlint flags as unsafe.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
9995027093
commit
671577245a
@ -3,6 +3,7 @@ package ghl
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
@ -153,7 +154,7 @@ func (h *AdminHandler) HandleSetLocationConfig(w http.ResponseWriter, r *http.Re
|
||||
|
||||
if err := h.store.UpdateLocationConfig(ctx, locationID, payload.SenderID, payload.CastAPIKey); err != nil {
|
||||
slog.Error("admin: update location config failed", "location_id", locationID, "err", err)
|
||||
if err.Error() == "location not found" {
|
||||
if errors.Is(err, store.ErrLocationNotFound) {
|
||||
http.Error(w, "location not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
@ -10,6 +10,9 @@ import (
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
)
|
||||
|
||||
// ErrLocationNotFound is returned when a location ID has no stored token record.
|
||||
var ErrLocationNotFound = errors.New("location not found")
|
||||
|
||||
type TokenRecord struct {
|
||||
LocationID string `bson:"location_id"`
|
||||
CompanyID string `bson:"company_id"`
|
||||
@ -99,7 +102,7 @@ func (s *Store) UpdateLocationConfig(ctx context.Context, locationID, senderID,
|
||||
return err
|
||||
}
|
||||
if res.MatchedCount == 0 {
|
||||
return errors.New("location not found")
|
||||
return ErrLocationNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user