Class: Yapper::ErrorProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/yapper/error.rb

Overview

This gem seems to monkey patch faraday to catch certain exceptions and even that attempt does not seem to be loaded anywhere, so instead we’ll catch the error on every request(and possibly elsewhere) and then pass the exception to this class who will figure out the proper high level exception to raise

Class Method Summary collapse

Class Method Details

.determine_exception(exception) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/yapper/error.rb', line 13

def self.determine_exception(exception)
  exception = exception
  message = exception.message
  status = exception.response[:status]
  headers = exception.response[:headers]

  case status.to_i
  when 400
    Yapper::BadRequest.new(error_message(message), headers)
  when 401
    Yapper::Unauthorized.new(error_message(message), headers)
  when 403
    Yapper::Forbidden.new(error_message(message), headers)
  when 404
    Yapper::NotFound.new(error_message(message), headers)
  when 429
    Yapper::TooManyRequests.new(error_message(message), headers)
  when 406
    Yapper::NotAcceptable.new(error_message(message), headers)
  when 500
    Yapper::InternalServerError.new(error_message("Something is technically wrong."), headers)
  when 502
    Yapper::BadGateway.new(error_message("Yammer is down or being upgraded."), headers)
  when 503
    Yapper::ServiceUnavailable.new(error_message("(__-){ Yammer is over capacity."), headers)
  else
    Exception.new("Unhandled Exception Status: #{status} - #{message}")
  end      
end

.new(exception) ⇒ Object



9
10
11
# File 'lib/yapper/error.rb', line 9

def self.new(exception)
  return self.determine_exception(exception)
end