Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly catching API exceptions #103

Closed
blorange2 opened this issue Jun 5, 2020 · 3 comments
Closed

Properly catching API exceptions #103

blorange2 opened this issue Jun 5, 2020 · 3 comments

Comments

@blorange2
Copy link

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Fixed in release 5.5.0

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

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

No branches or pull requests

3 participants