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

Library assumes all responses are JSON structured - they aren't #302

Closed
mdisimino opened this issue Oct 6, 2023 · 7 comments
Closed

Library assumes all responses are JSON structured - they aren't #302

mdisimino opened this issue Oct 6, 2023 · 7 comments
Labels

Comments

@mdisimino
Copy link

Issue summary

Rest/Base.php's request() method assumes all responses to be JSONs whereas some of them are HTML.

        **if ($statusCode < 200 || $statusCode >= 300)**
        {
                $message = "REST request failed";

                **$responseBody = $response->getDecodedBody();**
                if (!empty($responseBody["errors"]))
                {
                        $bodyErrors = json_encode($responseBody["errors"]);
                        $message .= ": {$bodyErrors}";
                }

                throw new RestResourceRequestException($message, $statusCode);
        }

Eg. for error codes 502/503/504, and possibly others, response is HTML, eg. <title>502 Bad Gateway</title>...

$response->getDecodedBody() will call json_decode() which will throw a JsonException which will prevent RestResourceRequestException from being thrown.

@sebastianpisula
Copy link

app.CRITICAL: JsonException: Syntax error in /vendor/shopify/shopify-api/src/Clients/HttpResponse.php:48 Stack trace: 
#0 /vendor/shopify/shopify-api/src/Clients/HttpResponse.php(48): json_decode('<!DOCTYPE html>...', true, 512, 4194304) 
#1 /vendor/shopify/shopify-api/src/Auth/OAuth.php(374): Shopify\Clients\HttpResponse->getDecodedBody() 
#2 /vendor/shopify/shopify-api/src/Auth/OAuth.php(136): Shopify\Auth\OAuth::fetchAccessToken(Array, Object(Shopify\Auth\Session)) 
#3 /vendor/company/shopify-bundle/src/Controller/Auth/AuthCallbackController.php(49): Shopify\Auth\OAuth::callback(Array, Array, Array) 
#4 /vendor/symfony/http-kernel/HttpKernel.php(163): Company\ShopifyBundle\Controller\Auth\AuthCallbackController->index(Object(Symfony\Component\HttpFoundation\Request), Object(Octolize\ShopifyBundle\Repository\ShopRepository), Object(Symfony\Bridge\Monolog\Logger), Object(Symfony\Component\EventDispatcher\EventDispatcher)) 
#5 /vendor/symfony/http-kernel/HttpKernel.php(74): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) 
#6 /vendor/symfony/http-kernel/Kernel.php(184): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#7 /vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php(35): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request)) 
#8 /vendor/autoload_runtime.php(29): Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run() 
#9 /public/index.php(5): require_once('/...') 
#10 {main} {"shop":"....myshopify.com"}

Copy link

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Dec 10, 2023
@sebastianpisula
Copy link

I still have problems

@github-actions github-actions bot removed the Stale label Dec 25, 2023
@mba242
Copy link

mba242 commented Feb 21, 2024

Same here.

Copy link

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Apr 22, 2024
Copy link

github-actions bot commented May 6, 2024

We are closing this issue because it has been inactive for a few months.
This probably means that it is not reproducible or it has been fixed in a newer version.
If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.

If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines

Thank you!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
@mderaspe
Copy link

The problem persists. You might want to reopen.

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

No branches or pull requests

4 participants