change from FooErr to ErrFoo

This commit is contained in:
yyasha 2024-01-22 15:55:26 +03:00
parent 58b8d016e8
commit 26845b5c82
1 changed files with 15 additions and 15 deletions

View File

@ -27,13 +27,13 @@ var PHPSESSID string
var parseKey string
var (
KeyNotFoundErr = errors.New("key not found")
CookieNotFoundErr = errors.New("cookie not found")
NotSuccessReqErr = errors.New("not success request")
EmptyLinkErr = errors.New("empty link")
RecipeExistsErr = errors.New("recipe already exists")
FailUpdatePHPSESSID = errors.New("failed to update PHPSESSID")
FailUpdateKEY = errors.New("failed to update KEY")
ErrKeyNotFound = errors.New("key not found")
ErrCookieNotFound = errors.New("cookie not found")
ErrNotSuccessReq = errors.New("not success request")
ErrEmptyLink = errors.New("empty link")
ErrRecipeExists = errors.New("recipe already exists")
ErrFailUpdatePHPSESSID = errors.New("failed to update PHPSESSID")
ErrFailUpdateKEY = errors.New("failed to update KEY")
)
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" {
err = GetPHPSESSID(log)
if err != nil {
return 0, fmt.Errorf("%s: %w", op, FailUpdatePHPSESSID)
return 0, fmt.Errorf("%s: %w", op, ErrFailUpdatePHPSESSID)
}
err = GetKey(log)
if err != nil {
return 0, fmt.Errorf("%s: %w", op, FailUpdateKEY)
return 0, fmt.Errorf("%s: %w", op, ErrFailUpdateKEY)
}
continue
}
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)
break
@ -134,7 +134,7 @@ func SavePage(log *slog.Logger, page int, ps pictureSaver, rs recipeSaver, rp re
defer wg.Done()
err = GetRecipe(&recipes[i], ps, rs, rp)
if err != nil {
if errors.Is(err, RecipeExistsErr) {
if errors.Is(err, ErrRecipeExists) {
log.Warn("Recipe already exists")
return
}
@ -151,7 +151,7 @@ func GetRecipe(r *models.Recipe, ps pictureSaver, rs recipeSaver, rp recipeProvi
const op = "parser.GetRecipe"
if r.Link == "" {
return fmt.Errorf("%s: %w", op, EmptyLinkErr)
return fmt.Errorf("%s: %w", op, ErrEmptyLink)
}
// send request
body, err := client.
@ -235,7 +235,7 @@ func GetRecipe(r *models.Recipe, ps pictureSaver, rs recipeSaver, rp recipeProvi
// check recipe exists
ex, err := rp.RecipeExists(context.Background(), r.Title) // interface!
if err != nil || ex {
return fmt.Errorf("%s: %w", op, RecipeExistsErr)
return fmt.Errorf("%s: %w", op, ErrRecipeExists)
}
// save picture
err = SaveRecipePicture(r, ps)
@ -289,7 +289,7 @@ func GetKey(log *slog.Logger) error {
return nil
}
return fmt.Errorf("%s: %w", op, KeyNotFoundErr)
return fmt.Errorf("%s: %w", op, ErrKeyNotFound)
}
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)
}