socialforge/app/api/mobile/middleware/error_handler.rb

20 lines
591 B
Ruby
Raw Normal View History

2014-12-10 17:29:39 +08:00
module Mobile
module Middleware
class ErrorHandler < Grape::Middleware::Base
def call!(env)
@env = env
begin
@app.call(@env)
rescue =>e
message = {status: 1, message: e.message }.to_json
puts(detail: e.backtrace.join("\n")) if Rails.env.development?
2014-12-10 17:29:39 +08:00
status = 200
headers = { 'Content-Type' => content_type }
Rack::Response.new([message], status, headers).finish
# throw :error, :message => e.message || options[:default_message], :status => 500
end
end
end
end
end