0
votes

I am using an OAuth library to connect to Etsy shop API. Code looks like this:

foreach ($transactions as $transactionSingle) {
    try {
        $oauth = new OAuth('xxx', 'xxx',
            OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
        $oauth->setToken($access_token, $access_token_secret);

        $data = $oauth->fetch("https://openapi.etsy.com/v2/users/".$transactionSingle['buyer_id']."/profile", null, OAUTH_HTTP_METHOD_GET);
        $json = $oauth->getLastResponse();
        $results = json_decode($json, true);
    } catch (OAuthException $e) {
        return null;
    }
}

Now the problem is that I run this code multiple times on foreach and if this URL is wrong and it fails to get any data - the whole function stops and doesn't continue anymore. It works perfectly until an old user ID is passed to URL and $oauth->fetch just reuturns message :

Invalid auth/bad request (got a 404, expected HTTP/1.1 20X or a redirect)

Any ideas how to continue to run the function despite any errors?

1
What do you mean by "I run this code inside an array"? - Erwin Moller
@ErwinMoller He runs it in a batch I think. - deEr.
Post updated, I meant that it runs multiple times on foreach. And the error just stops the whole cycle. - The50
OK thanks, clear now. Do you receive an Exception of maybe an error? (This can be confusing, depending on your PHP version.) Try to catch every exception catch (Exception $e) for starters. If that doesn't help, register your own errorhandler, and see if that catches it. - Erwin Moller
dumping $e doesn't give me anything, code even doesn't go to catch section I guess, it just dies after I make a request to URL with $oauth->fetch - The50

1 Answers

0
votes

The problem was in error cathing itself. Needed backslash on

catch (\OAuthException $e) {
}

Now the code catches the errors and continues if no code is provided inside catch.