jolicode / slack-php-api

:hash: PHP Slack Client based on the official OpenAPI specification
https://jolicode.github.io/slack-php-api/
MIT License
222 stars 56 forks source link

Throw exception when Slack returns error code #56

Closed pyrech closed 4 years ago

pyrech commented 4 years ago

Attempt at fixing #7

Slack documentation (https://api.slack.com/web) says :

All Web API responses contain a JSON object, which will always contain a top-level boolean property ok, indicating success or failure.

For failure results, the error property will contain a short machine-readable error code. In the case of problematic calls that could still be completed successfully, ok will be true and the warning property will contain a short machine-readable warning code (or comma-separated list of them, in the case of multiple warnings).

I propose to throw an exception when Slack returns false in ok and provides an error property. I'm not a big fan of doing an additional json_decode for all calls, but I don't see much alternatives :confused: