diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 635d38f..df5ca23 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -22,6 +22,13 @@ var client *httpclient.Client = httpclient.New().WithBaseURL(baseUrl) 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") +) + // SaveAllPages saves all pages to storage. func SaveAllPages(log slog.Logger) error { const op = "parser.SaveAllPages" @@ -69,8 +76,7 @@ func SavePage(log slog.Logger, page int) (int, error) { continue } if !resp.Success { - err = errors.New("not success request") - return 0, fmt.Errorf("%s: %w", op, err) + return 0, fmt.Errorf("%s: %w", op, NotSuccessReqErr) } body = strings.NewReader(resp.Data.Results) break @@ -113,7 +119,7 @@ func GetRecipe(r *models.Recipe) error { const op = "parser.GetRecipe" if r.Link == "" { - return fmt.Errorf("%s: %w", op, errors.New("empty link")) + return fmt.Errorf("%s: %w", op, EmptyLinkErr) } // send request body, err := client. @@ -167,11 +173,10 @@ func GetRecipe(r *models.Recipe) error { var advices []string s.Find("div.recipe-footer__additional-text>p").Each(func(i int, q *goquery.Selection) { if q.Find("br").Length() > 0 { - html, err := q.Html() - if err != nil { - - return fmt.Errorf("%s: %w", op, err) - } + html, _ := q.Html() + // if err != nil { + // return fmt.Errorf("%s: %w", op, err) + // } advice_list := q.SetHtml(strings.Replace(html, "
", "\n", -1)).Text() advices_arr := strings.Split(advice_list, "\n") var advices_arr_res []string = make([]string, 0, len(advices_arr)) @@ -272,9 +277,8 @@ func GetKey(log slog.Logger) error { log.Debug("New KEY =", parseKey) return nil } - err = errors.New("key not found") - return fmt.Errorf("%s: %w", op, err) + return fmt.Errorf("%s: %w", op, KeyNotFoundErr) } func GetPHPSESSID(log slog.Logger) error { @@ -301,7 +305,6 @@ func GetPHPSESSID(log slog.Logger) error { return nil } } - err = errors.New("cookie not found") - return fmt.Errorf("%s: %w", op, err) + return fmt.Errorf("%s: %w", op, CookieNotFoundErr) }