Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with ErrorList responses #779

Open
0xSekar opened this issue Sep 5, 2024 · 3 comments
Open

Issue with ErrorList responses #779

0xSekar opened this issue Sep 5, 2024 · 3 comments

Comments

@0xSekar
Copy link
Contributor

0xSekar commented Sep 5, 2024

Problem description:

The commit ec9522a fixed an issue with error responses defined as arrays instead of objects, but this change introduced an error in the call to GetListingOffersBatchRequest in ProductPricingV0 API.

In this particular case, The response at GetOffersResponse is an array of errors and not an ErrorList object.

The issue can be reproduced by sending an incorrect SKU or ASIN. I'm not sure yet how to revert the change for this specific response in the generator.

Original Response:

array(1) {
  ["responses"]=>
  array(1) {
    [0]=>
    array(4) {
      ["headers"]=>
      array(2) {
        ["x-amzn-RequestId"]=>
        string(36) "54c21e5e-dfdc-47f5-893a-0cdd3b4217d3"
        ["Date"]=>
        string(29) "Thu, 05 Sep 2024 14:49:21 GMT"
      }
      ["status"]=>
      array(2) {
        ["statusCode"]=>
        int(400)
        ["reasonPhrase"]=>
        string(11) "Bad Request"
      }
      ["body"]=>
      array(1) {
        ["errors"]=>
        array(1) {
          [0]=>
          array(3) {
            ["message"]=>
            string(60) "CCWB2001-FBM is an invalid SKU for marketplace ATVPDKIKX0DER"
            ["details"]=>
            string(0) ""
            ["code"]=>
            string(12) "InvalidInput"
          }
        }
      }
      ["request"]=>
      array(3) {
        ["MarketplaceId"]=>
        string(13) "ATVPDKIKX0DER"
        ["ItemCondition"]=>
        string(3) "New"
        ["SellerSKU"]=>
        string(0) ""
      }
    }
  }
}

Error:

PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function SellingPartnerApi\Seller\ProductPricingV0\Dto\ErrorList::__construct(), 0 passed in /var/www/gorilla/gorilla-cron/vendor/jlevers/selling-partner-api/src/Traits/Deserializes.php on line 76 and exactly 1 expected in /var/www/gorilla/gorilla-cron/vendor/jlevers/selling-partner-api/src/Seller/ProductPricingV0/Dto/ErrorList.php:22
Stack trace:
#0 /var/www/gorilla/gorilla-cron/vendor/jlevers/selling-partner-api/src/Traits/Deserializes.php(76): SellingPartnerApi\Seller\ProductPricingV0\Dto\ErrorList->__construct()
#1 vendor/jlevers/selling-partner-api/src/Traits/Deserializes.php(104): SellingPartnerApi\Dto::deserialize()
#2 vendor/jlevers/selling-partner-api/src/Traits/Deserializes.php(72): SellingPartnerApi\Response::deserializeValue()
#3 vendor/jlevers/selling-partner-api/src/Traits/Deserializes.php(104): SellingPartnerApi\Response::deserialize()
#4 vendor/jlevers/selling-partner-api/src/Traits/Deserializes.php(72): SellingPartnerApi\Dto::deserializeValue()
#5 vendor/jlevers/selling-partner-api/src/Traits/Deserializes.php(104): SellingPartnerApi\Dto::deserialize()
#6 vendor/jlevers/selling-partner-api/src/Traits/Deserializes.php(114): SellingPartnerApi\Response::deserializeValue()
#7 vendor/jlevers/selling-partner-api/src/Traits/Deserializes.php(72): SellingPartnerApi\Response::deserializeValue()
#8 vendor/jlevers/selling-partner-api/src/Seller/ProductPricingV0/Requests/GetListingOffersBatch.php(53): SellingPartnerApi\Response::deserialize()
#9 vendor/saloonphp/saloon/src/Http/Response.php(310): SellingPartnerApi\Seller\ProductPricingV0\Requests\GetListingOffersBatch->createDtoFromResponse()
#10 updateProductsLowestPricedOffers_Child.php(169): Saloon\Http\Response->dto()
#11 updateProductsLowestPricedOffers_Child.php(91): process()
#12 {main}

@christian71-stack
Copy link

I had the same problem. I then just used ->json() instead of ->dto()

@0xSekar
Copy link
Contributor Author

0xSekar commented Oct 18, 2024

Yes, that was my first solution. Then I manually updated the file so I can continue using my internal library (that uses ->dto()), but need to redo the changes on each update, so modifying the generator will be a better solution, just that I'm not sure how to do it. The file /src/Seller/ProductPricingV0/Responses/GetOffersResponse.php should look something like this:


/**
 * This file is auto-generated by Saloon SDK Generator
 * Generator: SellingPartnerApi\Generator\Generators\ResponseGenerator
 * Do not modify it directly.
 */

declare(strict_types=1);

namespace SellingPartnerApi\Seller\ProductPricingV0\Responses;

use SellingPartnerApi\Response;
use SellingPartnerApi\Seller\ProductPricingV0\Dto\Error;
use SellingPartnerApi\Seller\ProductPricingV0\Dto\GetOffersResult;

final class GetOffersResponse extends Response
{
    protected static array $complexArrayTypes = ['errors' => Error::class];

    /**
     * @param  ?ErrorList  $errors  A list of error responses returned when a request is unsuccessful.
     */
    public function __construct(
        public readonly ?GetOffersResult $payload = null,
        public readonly ?array $errors = null,
    ) {}
}

@p3le
Copy link

p3le commented Nov 7, 2024

I can confirm existence of this issue. Can we expect a fix implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants