aki017 / slack-ruby-gem

A Ruby wrapper for the Slack API
MIT License
242 stars 79 forks source link

Raise exceptions on responses from slack #17

Closed dblock closed 9 years ago

dblock commented 9 years ago

Slack responses and errors are standardized, why don't we raise a specific exception when something fails and do it "the ruby way" instead of returning a hash on failure that needs to be parsed every single time?

Happy to contribute that. For now I just monkey patch as such:

module Slack
  module Request
    private

    alias_method :_request, :request

    def request(method, path, options)
      response = _request(method, path, options)
      if response.is_a?(Hash)
        unless response['ok']
          fail response['error']
        end
      end
      response
    end
  end
end
dblock commented 9 years ago

@aki017 What do you think about this? I am happy to contribute a PR.

aki017 commented 9 years ago

@dblock very nice idea!

dblock commented 9 years ago

@aki017 PR in https://github.com/aki017/slack-ruby-gem/pull/27.