Sha256: 39de3c5db8c74286507fbb02c2d67af191e7e1348a2e3556188124c3dd200a6b
Contents?: true
Size: 1.28 KB
Versions: 7
Compression:
Stored size: 1.28 KB
Contents
require 'json' module ChatWork class ChatWorkError < StandardError def self.from_response(status, body) # HTTP status 204 don't have body. return APIError.new(status, "") if status == 204 hash = begin JSON.load(body) rescue JSON::ParserError => e return ChatWork::APIConnectionError.new("Response JSON is broken. #{e.message}: #{body}", e) end unless hash['errors'] return APIConnectionError.new("Invalid response #{body}") end APIError.new(status, hash["errors"]) end attr_reader :status attr_reader :error_response def initialize(message, status = nil, error_response = nil) @status, @error_response = status, error_response super(message) end end class APIConnectionError < ChatWorkError def self.faraday_error(e) new("Connection with ChatWork API server failed. #{e.message}", e) end attr_reader :original_error def initialize(message, original_error) @original_error = original_error super(message) end end class APIError < ChatWorkError attr_reader :errors def initilize(message, error_response) @errors = error_response["errors"] super(error_response["message"], status, error_response) end end end
Version data entries
7 entries across 7 versions & 1 rubygems