docusign / docusign-esign-php-client

The Official Docusign PHP Client Library used to interact with the eSign REST API. Send, sign, and approve documents using this client.
https://www.docusign.com/devcenter
MIT License
198 stars 123 forks source link

Properly catching API exceptions #103

Closed blorange2 closed 3 years ago

blorange2 commented 4 years ago

In my application there is a small chance of error when sending, so I wrap this in a try catch block and catch a standard Exception as $exception.

So when I do $exception->getResponseBody() instead of getting on object, I get a string like so:


O:8:"stdClass":2:{s:9:"errorCode";s:19:"TEMPLATE_ID_INVALID";s:7:"message";s:20:"Invalid template ID.";}

I want the message attribute but the response body is not an object.

I also tried json decoding it. Any ideas?

LarryKlugerDS commented 4 years ago

For the error you encountered, $exception->getResponseBody() returned a serialized object. (The object was created by the JSON error response.)

See the source.

So in this case, you'd unserialize it back into a PHP object.

But there can also be error responses with string response bodies. In those cases, the $exception->getResponseBody() would return the response body.

Since an SDK client app can't tell if the string should be unserialized or not, and unserialize is a dangerous method (see the docs), I have filed an enhancement request to always return the responseBody as a string. Then the SDK client can handle the JSON if it wants to with no unserialize method needed. Internal ticket DCM-4286

dbbrahmbhatt commented 3 years ago

Hi @blorange2 , we have fixed this for the forthcoming 5.5 release. Currently thats the 5.5.0-RC release -- RC means Release Candidate.

To install it: composer require docusign/esign-client:v5.5.0-rc

Please validate from your side and let us know if you still face the issue.

LarryKlugerDS commented 3 years ago

Fixed in release 5.5.0

Please re-open this issue if this is still a problem. Thank you