kbsali / php-redmine-api

A simple PHP Redmine API client, Object Oriented
MIT License
421 stars 183 forks source link

Return of requests is "Error deconding body as JSON: ..." if there is an SerializerException #431

Open asdfklgash opened 16 hours ago

asdfklgash commented 16 hours ago

Instead of (re-)throwing a new / the existing exception of JsonSerializer there is a string returned (not everywhere but in some methods):

string(41) "Error decoding body as JSON: Syntax error"

That's a bit tricky as we cannot catch the error and handle it. So we've also to check the return of a call (i. e. getApi('issue')->show(...)).

Art4 commented 15 hours ago

Hey, this happens mainly for BC reasons while using deprecated methods. If you could tell us how us are using the library I maybe can show you an alternative.

Update: Sorry, I just saw to snippet. The most API classes are returning string|bool on error for BC reasons. This cannot be changed atm without a breaking change and is planned for v3. However I'm planning to implement this as a forward compatible feature by introducing something like a global PHP_REDMINE_API_THROW_EXCEPTIONS = true; constant.