class ATSD::Middleware::ErrorsHandlerMiddleware

Middleware to raise error on request fail and possibly catch error message from API.

Constants

HTTP_STATUS_CODES

HTTP status codes with messages generated by

“`bash

curl -s www.iana.org/assignments/http-status-codes/http-status-codes-1.csv | \
ruby -ne 'm = /^(\d{3}),(?!Unassigned|\(Unused\))([^,]+)/.match($_) and \
puts "#{m[1]} => \x27#{m[2].strip}\x27,"'

“`

Public Instance Methods

call(environment) click to toggle source
# File lib/atsd/middleware/errors_handler.rb, line 76
def call(environment)
  @app.call(environment).on_complete do |env|
    unless env.success?
      message = env.body['error'] || HTTP_STATUS_CODES[env.status]
      fail APIError.new(env), message
    end
  end
end