feat: update function names and logic for category error handling

This commit is contained in:
2025-08-20 18:12:06 +03:00
parent 8120414e02
commit 61775a6bb8

View File

@@ -254,7 +254,7 @@ func (r *apiRepository) CalculateProductTariffs(ctx context.Context, marketplace
func (r *apiRepository) setTariffsRateLimit() { func (r *apiRepository) setTariffsRateLimit() {
ym.SetPathLimit("/tariffs/calculate", rateLimitWindow, tariffsRateLimit) ym.SetPathLimit("/tariffs/calculate", rateLimitWindow, tariffsRateLimit)
} }
func getCategoriesError(bodyData string) []int64 { func GetCategoriesError(bodyData string) []int64 {
var result []int64 var result []int64
for _, v := range gjson.Get(bodyData, "errors.#.message").Array() { for _, v := range gjson.Get(bodyData, "errors.#.message").Array() {
errorMessage := v.String() errorMessage := v.String()
@@ -280,7 +280,7 @@ func getCategoriesError(bodyData string) []int64 {
func filterOffersByCategories(offers []*pb.CalculateProductTariffsRequest_Offer, categories []int64) []*pb.CalculateProductTariffsRequest_Offer { func filterOffersByCategories(offers []*pb.CalculateProductTariffsRequest_Offer, categories []int64) []*pb.CalculateProductTariffsRequest_Offer {
return lo.Filter(offers, func(offer *pb.CalculateProductTariffsRequest_Offer, _ int) bool { return lo.Filter(offers, func(offer *pb.CalculateProductTariffsRequest_Offer, _ int) bool {
return lo.Contains(categories, offer.CategoryId) return !lo.Contains(categories, offer.CategoryId)
}) })
} }
@@ -321,7 +321,7 @@ func (r *apiRepository) processTariffChunk(ctx context.Context, client *ymclient
return nil, fmt.Errorf("failed to read response body for chunk %d: %w", chunkIndex+1, httpErr) return nil, fmt.Errorf("failed to read response body for chunk %d: %w", chunkIndex+1, httpErr)
} }
fmt.Printf("Error response for chunk %d: %s\n", chunkIndex+1, string(bodyData)) fmt.Printf("Error response for chunk %d: %s\n", chunkIndex+1, string(bodyData))
categoriesErrors := getCategoriesError(string(bodyData)) categoriesErrors := GetCategoriesError(string(bodyData))
if len(categoriesErrors) == 0 { if len(categoriesErrors) == 0 {
return nil, fmt.Errorf("failed to call Yandex Market API for chunk %d: %w", chunkIndex+1, err) return nil, fmt.Errorf("failed to call Yandex Market API for chunk %d: %w", chunkIndex+1, err)
} }