class DeskApi::Response::RaiseError

The {DeskApi::Response::RaiseError} middleware raises errors that happen during the API request

@author Thomas Stachl <tstachl@salesforce.com> @copyright Copyright © 2013-2016 Salesforce.com @license BSD 3-Clause License

Public Class Methods

new(app, klass) click to toggle source

Initializes this middleware with the specific class.

Calls superclass method
# File lib/desk_api/response/raise_error.rb, line 64
def initialize(app, klass)
  @klass = klass
  super(app)
end

Public Instance Methods

on_complete(env) click to toggle source

Checks the status code and raises the error if there is a error class found for the status code

@raise [DeskApi::Error]

# File lib/desk_api/response/raise_error.rb, line 57
def on_complete(env)
  status_code = env[:status].to_i
  error_class = @klass.errors[status_code]
  raise error_class.from_response(env) if error_class
end