Git Product home page Git Product logo

Comments (5)

phena109 avatar phena109 commented on May 21, 2024 1

Old trick of try...catch does the job for me

try {
    $result = $hs->contacts()->getByEmail($email);
} catch (BadRequest $exc) {
    if ($exc->getCode() == 404) {

    }
}

from hubspot-php.

dsoares avatar dsoares commented on May 21, 2024 1

What would be the expected behavior?
From a previous commit (ebc8fb5), it was decided that Client::request would rethrow Guzzle exceptions (and not return a Response). So, i think @phena109 is right (not an old trick, it's the right way to do it, unless you change your thoughts about how hubspot-php should deal with Guzzle exceptions or 4xx / 5xx responses).

from hubspot-php.

mohammedanis avatar mohammedanis commented on May 21, 2024 1

This worked for me... In hubspot-php\src\Resources\Contacts.php, Line number 276 disable the http errors by replacing the line with this ['http_errors' => false],
Finally, It looks like this,

return $this->client->request(
    'get',
    $endpoint,
    ['http_errors' => false],
    build_query_string($params)
);

from hubspot-php.

gmaniac avatar gmaniac commented on May 21, 2024

+1

from hubspot-php.

ksvirkou-hubspot avatar ksvirkou-hubspot commented on May 21, 2024

Hi everyone
you can pass http_errors false and Guzzle won’t throw errors

$hubspot = Factory::createWithOAuth2Token(
    'token', 
    null,
    ['http_errors' => false]
);
$response = $hubspot->contacts()->getByEmail("[email protected]");

response

object(SevenShores\Hubspot\Http\Response)#18 (2) {
  ["data"]=>
  object(stdClass)#34 (5) {
    ["status"]=>
    string(5) "error"
    ["message"]=>
    string(22) "contact does not exist"
    ["correlationId"]=> ""
    ["errors"]=>
    array(1) {
      [0]=>
      object(stdClass)#35 (1) {
        ["message"]=>
        string(46) "The contact e:[email protected] does not exist."
      }
    }
    ["category"]=>
    string(16) "OBJECT_NOT_FOUND"
  } ...

from hubspot-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.