Giter Club home page Giter Club logo

Comments (7)

nurazem avatar nurazem commented on June 27, 2024

@josler Can you have a look at this? The response is indeed not a valid JSON.

from intercom-php.

dehora avatar dehora commented on June 27, 2024

Thanks @frankmichel. @nurazem @josler Ideally the server shouldn't return a whitespace artifact, but because the events resource doesn't return JSON the client shouldn't be looking for any on a 2xx response. Looks like the client will need a patch, marking as a bug.

from intercom-php.

nurazem avatar nurazem commented on June 27, 2024

Hi @dehora. I have looked into the issue and I think that the problem is on the server side. Although, the resource doesn't return JSON, the response's Content-Type header is set to 'application/json'. As you can see below Guzzle is trying to parse the body based on that header.
In Guzzle/Service/Command/DefaultResponseParser.php

public function parse(CommandInterface $command)
{
    $response = $command->getRequest()->getResponse();

    // Account for hard coded content-type values specified in service descriptions
    if ($contentType = $command['command.expects']) {
        $response->setHeader('Content-Type', $contentType);
    } else {
        $contentType = (string) $response->getHeader('Content-Type');
    }

    return $this->handleParsing($command, $response, $contentType);
}

protected function handleParsing(CommandInterface $command, Response $response, $contentType)
{
    $result = $response;
    if ($result->getBody()) {
        if (stripos($contentType, 'json') !== false) {
            $result = $result->json();
        } elseif (stripos($contentType, 'xml') !== false) {
            $result = $result->xml();
        }
    }

    return $result;
}

from intercom-php.

aaronfessler avatar aaronfessler commented on June 27, 2024

I am experiencing this bug as well.

from intercom-php.

webeng avatar webeng commented on June 27, 2024

Yep, me too.

from intercom-php.

aaronfessler avatar aaronfessler commented on June 27, 2024

Hey @josler @nurazem what's the ETA on fixing this? It is pretty easy to repeat and is a showstopper:

use Intercom\IntercomBasicAuthClient;
$intercom = IntercomBasicAuthClient::factory(array(
    'app_id' => "XXXX",
    'api_key' => "YYYY"
));

$intercom->createEvent(array('user_id' => 1, 'created_at'=> time(),'event_name' => 'Code is bogus!'))

Yields this:

Fatal error: Uncaught exception 'Guzzle\Common\Exception\RuntimeException' with message 'Unable to parse response body into JSON: 4' in /Users/aaron/Sites/twine/lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php:861
Stack trace:
#0 /Users/aaron/Sites/twine/lib/vendor/guzzle/guzzle/src/Guzzle/Service/Command/DefaultResponseParser.php(47): Guzzle\Http\Message\Response->json()
#1 /Users/aaron/Sites/twine/lib/vendor/guzzle/guzzle/src/Guzzle/Service/Command/OperationResponseParser.php(80): Guzzle\Service\Command\DefaultResponseParser->handleParsing(Object(Guzzle\Service\Command\OperationCommand), Object(Guzzle\Http\Message\Response), 'application/jso...')
#2 /Users/aaron/Sites/twine/lib/vendor/guzzle/guzzle/src/Guzzle/Service/Command/DefaultResponseParser.php(39): Guzzle\Service\Command\OperationResponseParser->handleParsing(Object(Guzzle\Service\Command\OperationCommand), Object(Guzzle\Http\Message\Response), 'application/jso...')
#3 /Users/aaron/Sites/twine/lib/vendor/guzzle/guzzle/src/Guzzle/Service/Command/Opera in /Users/aaron/Sites/twine/lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php on line 861

Guzzle 4.2.3
Intercom 1.0.0-b3

from intercom-php.

josler avatar josler commented on June 27, 2024

Fixed with v1.0.0-b4!

Thanks.

from intercom-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.