class Locomotive::Coal::Error
Take inspiration from this repository: github.com/vigeland/hooty
Attributes
response[R]
Public Class Methods
from_response(response)
click to toggle source
# File lib/locomotive/coal/error.rb, line 19 def self.from_response(response) status = response.status if klass = case status.to_i when 401 then Locomotive::Coal::UnauthorizedError when 404 then Locomotive::Coal::UnknownResourceError when 413 then Locomotive::Coal::FileTooBigError when 422 then Locomotive::Coal::InvalidResourceError when 429 then Locomotive::Coal::TooManyRequestsError when 500 then Locomotive::Coal::ServerSideError else Error end klass.new(response) end end
new(response = nil)
click to toggle source
Calls superclass method
# File lib/locomotive/coal/error.rb, line 10 def initialize(response = nil) @response = response super(build_message) end
Public Instance Methods
body()
click to toggle source
# File lib/locomotive/coal/error.rb, line 15 def body @response.body || {} end
Private Instance Methods
build_message()
click to toggle source
# File lib/locomotive/coal/error.rb, line 36 def build_message @response ? body['error'] : nil end