Sha256: 365c79be1603fc53ec62e4f7374a95d7582bd9a2c5253efaa0ea0700f49bcff9
Contents?: true
Size: 1.41 KB
Versions: 2
Compression:
Stored size: 1.41 KB
Contents
class Fanforce class Error < StandardError; attr_accessor :path, :query_params, :request, :response, :request_url def initialize(response, request, path, query_params) @query_params = query_params @path = path @request = request begin @response = MultiJson.load(response, :symbolize_keys => true) rescue Exception => e @response = "JSON decode error in Gem: #{e.message}" end @request_url = "#{@path}?#{@query_params.to_param}" super(@response.is_a?(Hash) ? @response[:msg] : @response) end def curl_command case @request.method when :get "curl \"#{@path}?#{@query_params.to_param}\"" when :post "curl -X POST -d \"#{@query_params.to_param}\" #{@path}" when :put "curl -X PUT -d \"#{@query_params.to_param}\" #{@path.to_json}" when :delete "curl --request DELETE \"#{@path}?#{@query_params.to_param}\"" else "Could not create curl command because request method was unknown: #{@request.method}" end end def code() end end class BadRequestError < Error; def code() 400 end end class ForbiddenError < Error; def code() 403 end end class NotFoundError < Error; def code() 404 end end class UnprocessableEntityError < Error; def code() 422 end end class UnknownError < Error; def code() 500 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fanforce-0.3.0 | lib/fanforce/errors.rb |
fanforce-0.2.9 | lib/fanforce/errors.rb |