feat: update function names and logic for category error handling
This commit is contained in:
@@ -254,7 +254,7 @@ func (r *apiRepository) CalculateProductTariffs(ctx context.Context, marketplace
|
||||
func (r *apiRepository) setTariffsRateLimit() {
|
||||
ym.SetPathLimit("/tariffs/calculate", rateLimitWindow, tariffsRateLimit)
|
||||
}
|
||||
func getCategoriesError(bodyData string) []int64 {
|
||||
func GetCategoriesError(bodyData string) []int64 {
|
||||
var result []int64
|
||||
for _, v := range gjson.Get(bodyData, "errors.#.message").Array() {
|
||||
errorMessage := v.String()
|
||||
@@ -280,7 +280,7 @@ func getCategoriesError(bodyData string) []int64 {
|
||||
|
||||
func filterOffersByCategories(offers []*pb.CalculateProductTariffsRequest_Offer, categories []int64) []*pb.CalculateProductTariffsRequest_Offer {
|
||||
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)
|
||||
}
|
||||
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 {
|
||||
return nil, fmt.Errorf("failed to call Yandex Market API for chunk %d: %w", chunkIndex+1, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user