class Slack::Error
Public Class Methods
from_response(response)
click to toggle source
Returns the appropriate Slack::Error
sublcass based on error message
@param [Hash] response HTTP response @return [Slack::Error]
# File lib/slack/error.rb, line 9 def self.from_response(response) status = response[:status].to_i headers = response[:response_headers] body = JSON.parse(response.body) ok = ["true", 1].include? body['ok'] error = body['error'] unless ok if klass = case error when "invalid_auth" then Slack::InvalidAuth when "account_inactive" then Slack::AccountInactive when "channel_not_found" then Slack::ChannelNotFound when "is_archived" then Slack::IsArchived end klass.new(response) end end end
new(response=nil)
click to toggle source
Calls superclass method
# File lib/slack/error.rb, line 28 def initialize(response=nil) @response = response super(build_error_message) end
Public Instance Methods
build_error_message()
click to toggle source
# File lib/slack/error.rb, line 33 def build_error_message return nil if @response.nil? message = "#{@response['method'].to_s.upcase} " message << "#{@response['url'].to_s}: " message << "#{@response['status']} - " message end