Skip to content
This repository has been archived by the owner on Oct 24, 2020. It is now read-only.

Call to method WebHook::getAllErrorMessages() causes an exception #4

Closed
rtarnaud opened this issue Nov 11, 2015 · 3 comments
Closed
Labels

Comments

@rtarnaud
Copy link

Hi,

I think there's another issue with the getAllErrorMessages method of WebHook. I invoke it after a standard web hook creation:

        $webHook = new \BlockCypher\Api\WebHook();
        $webHook->setUrl($url);
        $webHook->setEvent('tx-confirmation');
        $webHook->setHash($hash);

        $apiContext = new \BlockCypher\Rest\ApiContext(new \BlockCypher\Auth\SimpleTokenCredential($this->blockcypherToken));

        $webHookClient = new \BlockCypher\Client\WebHookClient($apiContext);
        $webHookModified = $webHookClient->create($webHook);

        $webHookModified->getAllErrorMessages();

Fair enough, I spotted this bug recently with an invalid hash ($hash) but I think the call to the method also failed with a valid hash.

FYI, here's the call stack on crash:

{
    "error": {
        "code": 500,
        "message": "Internal Server Error",
        "exception": [{
                "message": "Invalid argument supplied for foreach()",
                "class": "ErrorException",
                "trace": [{
                        "namespace": "",
                        "short_class": "",
                        "class": "",
                        "type": "",
                        "function": "",
                        "file": "C:\\wamp\\www\\XXX\\vendor\\blockcypher\\php-client\\lib\\BlockCypher\\Common\\BlockCypherBaseModel.php",
                        "line": 87,
                        "args": []
                    }, {
                        "namespace": "",
                        "short_class": "AppKernel",
                        "class": "AppKernel",
                        "type": "->",
                        "function": "{closure}",
                        "file": "C:\\wamp\\www\\XXX\\vendor\\blockcypher\\php-client\\lib\\BlockCypher\\Common\\BlockCypherBaseModel.php",
                        "line": 87,
                        "args": [["string", "2"], ["string", "Invalid argument supplied for foreach()"], ["string", "C:\\wamp\\www\\XXX\\vendor\\blockcypher\\php-client\\lib\\BlockCypher\\Common\\BlockCypherBaseModel.php"], ["string", "87"], ["array", {
                                    "errorMessages": ["array", []]
                                }]]
                    }, {
                        "namespace": "BlockCypher\\Common",
                        "short_class": "BlockCypherBaseModel",
                        "class": "BlockCypher\\Common\\BlockCypherBaseModel",
                        "type": "->",
                        "function": "getErrorMessages",
                        "file": "C:\\wamp\\www\\XXX\\vendor\\blockcypher\\php-client\\lib\\BlockCypher\\Common\\BlockCypherBaseModel.php",
                        "line": 75,
                        "args": []
                    }, {
                        "namespace": "BlockCypher\\Common",
                        "short_class": "BlockCypherBaseModel",
                        "class": "BlockCypher\\Common\\BlockCypherBaseModel",
                        "type": "->",
                        "function": "getAllErrorMessages",
                        "file": "C:\\wamp\\www\\XXX\\src\\XXX\\CurrencyBundle\\Controller\\TransactionRestController.php",
                        "line": 36,
                        "args": []
                    }, {
                        "namespace": "XXX\\CurrencyBundle\\Controller",
                        "short_class": "TransactionRestController",
                        "class": "XXX\\CurrencyBundle\\Controller\\TransactionRestController",
                        "type": "->",
                        "function": "postTransactionFundingAction",
                        "file": null,
                        "line": null,
                        "args": [["object", "Symfony\\Component\\HttpFoundation\\Request"]]
                    }, {
                        "namespace": "",
                        "short_class": "",
                        "class": "",
                        "type": "",
                        "function": "call_user_func_array",
                        "file": "C:\\wamp\\www\\XXX\\app\\bootstrap.php.cache",
                        "line": 3109,
                        "args": [["array", [["object", "XXX\\CurrencyBundle\\Controller\\TransactionRestController"], ["string", "postTransactionFundingAction"]]], ["array", [["object", "Symfony\\Component\\HttpFoundation\\Request"]]]]
                    }, {
                        "namespace": "Symfony\\Component\\HttpKernel",
                        "short_class": "HttpKernel",
                        "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
                        "type": "->",
                        "function": "handleRaw",
                        "file": "C:\\wamp\\www\\XXX\\app\\bootstrap.php.cache",
                        "line": 3071,
                        "args": [["object", "Symfony\\Component\\HttpFoundation\\Request"], ["string", "1"]]
                    }, {
                        "namespace": "Symfony\\Component\\HttpKernel",
                        "short_class": "HttpKernel",
                        "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
                        "type": "->",
                        "function": "handle",
                        "file": "C:\\wamp\\www\\XXX\\app\\bootstrap.php.cache",
                        "line": 3222,
                        "args": [["object", "Symfony\\Component\\HttpFoundation\\Request"], ["string", "1"], ["boolean", true]]
                    }, {
                        "namespace": "Symfony\\Component\\HttpKernel\\DependencyInjection",
                        "short_class": "ContainerAwareHttpKernel",
                        "class": "Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel",
                        "type": "->",
                        "function": "handle",
                        "file": "C:\\wamp\\www\\XXX\\app\\bootstrap.php.cache",
                        "line": 2444,
                        "args": [["object", "Symfony\\Component\\HttpFoundation\\Request"], ["string", "1"], ["boolean", true]]
                    }, {
                        "namespace": "Symfony\\Component\\HttpKernel",
                        "short_class": "Kernel",
                        "class": "Symfony\\Component\\HttpKernel\\Kernel",
                        "type": "->",
                        "function": "handle",
                        "file": "C:\\wamp\\www\\XXX\\web\\app_dev.php",
                        "line": 28,
                        "args": [["object", "Symfony\\Component\\HttpFoundation\\Request"]]
                    }]
            }]
    }
}

Any ideas on this one?

Thanks!

@josecelano
Copy link
Contributor

Hi @rtarnaud . Sorry I have been very busy. It's a bug in this method:

``` php`
public function getErrorMessages()
{
$errorMessages = array();
if (is_array($this->errors)) { // <!-- FIXED
foreach ($this->errors as $error) {
$errorMessages[] = $error->getError();
}
}
return $errorMessages;
}


If the json response does not contain any error this methods fails. I am gooing to fix it, add a test, and build a new release. In the mean time you can check if `getErrors()`  returns an array before calling `getErrorMessages()` mthod.

Thanks you very much.

@rtarnaud
Copy link
Author

Ok, thanks!

josecelano pushed a commit that referenced this issue Jan 12, 2016
@josecelano
Copy link
Contributor

Fixed but I still have to generate a new release with other minor bug fixes.

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

No branches or pull requests

2 participants