change from FooErr to ErrFoo
This commit is contained in:
parent
58b8d016e8
commit
26845b5c82
|
@ -27,13 +27,13 @@ var PHPSESSID string
|
||||||
var parseKey string
|
var parseKey string
|
||||||
|
|
||||||
var (
|
var (
|
||||||
KeyNotFoundErr = errors.New("key not found")
|
ErrKeyNotFound = errors.New("key not found")
|
||||||
CookieNotFoundErr = errors.New("cookie not found")
|
ErrCookieNotFound = errors.New("cookie not found")
|
||||||
NotSuccessReqErr = errors.New("not success request")
|
ErrNotSuccessReq = errors.New("not success request")
|
||||||
EmptyLinkErr = errors.New("empty link")
|
ErrEmptyLink = errors.New("empty link")
|
||||||
RecipeExistsErr = errors.New("recipe already exists")
|
ErrRecipeExists = errors.New("recipe already exists")
|
||||||
FailUpdatePHPSESSID = errors.New("failed to update PHPSESSID")
|
ErrFailUpdatePHPSESSID = errors.New("failed to update PHPSESSID")
|
||||||
FailUpdateKEY = errors.New("failed to update KEY")
|
ErrFailUpdateKEY = errors.New("failed to update KEY")
|
||||||
)
|
)
|
||||||
|
|
||||||
type pictureSaver interface {
|
type pictureSaver interface {
|
||||||
|
@ -95,16 +95,16 @@ func SavePage(log *slog.Logger, page int, ps pictureSaver, rs recipeSaver, rp re
|
||||||
if resp.Message == "Could not load config" {
|
if resp.Message == "Could not load config" {
|
||||||
err = GetPHPSESSID(log)
|
err = GetPHPSESSID(log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("%s: %w", op, FailUpdatePHPSESSID)
|
return 0, fmt.Errorf("%s: %w", op, ErrFailUpdatePHPSESSID)
|
||||||
}
|
}
|
||||||
err = GetKey(log)
|
err = GetKey(log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("%s: %w", op, FailUpdateKEY)
|
return 0, fmt.Errorf("%s: %w", op, ErrFailUpdateKEY)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !resp.Success {
|
if !resp.Success {
|
||||||
return 0, fmt.Errorf("%s: %w", op, NotSuccessReqErr)
|
return 0, fmt.Errorf("%s: %w", op, ErrNotSuccessReq)
|
||||||
}
|
}
|
||||||
body = strings.NewReader(resp.Data.Results)
|
body = strings.NewReader(resp.Data.Results)
|
||||||
break
|
break
|
||||||
|
@ -134,7 +134,7 @@ func SavePage(log *slog.Logger, page int, ps pictureSaver, rs recipeSaver, rp re
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
err = GetRecipe(&recipes[i], ps, rs, rp)
|
err = GetRecipe(&recipes[i], ps, rs, rp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, RecipeExistsErr) {
|
if errors.Is(err, ErrRecipeExists) {
|
||||||
log.Warn("Recipe already exists")
|
log.Warn("Recipe already exists")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ func GetRecipe(r *models.Recipe, ps pictureSaver, rs recipeSaver, rp recipeProvi
|
||||||
const op = "parser.GetRecipe"
|
const op = "parser.GetRecipe"
|
||||||
|
|
||||||
if r.Link == "" {
|
if r.Link == "" {
|
||||||
return fmt.Errorf("%s: %w", op, EmptyLinkErr)
|
return fmt.Errorf("%s: %w", op, ErrEmptyLink)
|
||||||
}
|
}
|
||||||
// send request
|
// send request
|
||||||
body, err := client.
|
body, err := client.
|
||||||
|
@ -235,7 +235,7 @@ func GetRecipe(r *models.Recipe, ps pictureSaver, rs recipeSaver, rp recipeProvi
|
||||||
// check recipe exists
|
// check recipe exists
|
||||||
ex, err := rp.RecipeExists(context.Background(), r.Title) // interface!
|
ex, err := rp.RecipeExists(context.Background(), r.Title) // interface!
|
||||||
if err != nil || ex {
|
if err != nil || ex {
|
||||||
return fmt.Errorf("%s: %w", op, RecipeExistsErr)
|
return fmt.Errorf("%s: %w", op, ErrRecipeExists)
|
||||||
}
|
}
|
||||||
// save picture
|
// save picture
|
||||||
err = SaveRecipePicture(r, ps)
|
err = SaveRecipePicture(r, ps)
|
||||||
|
@ -289,7 +289,7 @@ func GetKey(log *slog.Logger) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("%s: %w", op, KeyNotFoundErr)
|
return fmt.Errorf("%s: %w", op, ErrKeyNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPHPSESSID(log *slog.Logger) error {
|
func GetPHPSESSID(log *slog.Logger) error {
|
||||||
|
@ -317,5 +317,5 @@ func GetPHPSESSID(log *slog.Logger) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("%s: %w", op, CookieNotFoundErr)
|
return fmt.Errorf("%s: %w", op, ErrCookieNotFound)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue