Sha256: 200cd90d3cb5754046a908ddb20d7dd2850d3cacaf6286530828b2f8169a328e

Contents?: true

Size: 664 Bytes

Versions: 1

Compression:

Stored size: 664 Bytes

Contents

require 'multi_json'
require 'rack'

module MpWeixin
  class Error < StandardError
    attr_reader :response, :code, :description

    # standard error values include:
    # :invalid_request, :invalid_client, :invalid_token, :invalid_grant, :unsupported_grant_type, :invalid_scope
    def initialize(response)
      response.error = self
      @response = response

      message = []

      if response.parsed.is_a?(Hash)
        @code = response.parsed['error']
        @description = response.parsed['error_description']
        message << "#{@code}: #{@description}"
      end

      message << response.body

      super(message.join("\n"))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mp_weixin-0.1.0 lib/mp_weixin/error.rb