class Rack::PactBroker::Convert404ToHal

Public Class Methods

new(app) click to toggle source
# File lib/rack/pact_broker/convert_404_to_hal.rb, line 5
def initialize app
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/pact_broker/convert_404_to_hal.rb, line 9
def call env
  response = @app.call(env)

  if response.first == 404 && response[1]["Content-Type"] == "text/html" && !(env["HTTP_ACCEPT"] =~ /html|javascript|css/)
    [404, { "Content-Type" => "application/hal+json;charset=utf-8"},[]]
  else
    response
  end
end