Class: Sheep::ErrorResponse

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

Instance Method Summary collapse

Constructor Details

#initialize(app = nil) ⇒ ErrorResponse

Returns a new instance of ErrorResponse.



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

def initialize(app = nil)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sheep/error.rb', line 13

def call(env)
  status, headers, body = @app.call(env)
  case status
  when 200, 201, 301, 302
  when 400
    raise Sheep::BadRequest.new(body['error'] || body['errors'])
  when 404
    raise Sheep::NotFound
  else
    raise Sheep::UnknownError.new(body)
  end
  return status, headers, body
end