storyblok / storyblok-php-client

Storyblok - PHP Client
https://www.storyblok.com
MIT License
33 stars 37 forks source link

Improve exception handling #88

Open sharkodlak opened 1 year ago

sharkodlak commented 1 year ago

Exception can be enhanced by passing causing exception as $previous when ApiException is created. Now it's impossible to get API response body from ApiException.


Expected Behavior

I'd like to get API response body from ApiException $e.

try { ... } catch (ApiException $e) (string) $e->getPrevious()->getResponse()->getBody(); }

Current Behavior

It's impossible to call $e->getPrevious()->... because previous exception is't stored.

Steps to Reproduce

  1. Set editMode: $client->editMode(true);
  2. Call $client->getStories($options)->getBody(); Now ApiException is thrown, because client is unauthorized.
  3. Try to obtain serious information what's going on from ApiException $e.
roberto-butti commented 1 year ago

Thank you @sharkodlak for the valuable feedback. Let me check it and come back to you with more information.