2016-07-25 16:59:52 +08:00
|
|
|
#coding=utf-8
|
|
|
|
|
|
|
|
|
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
|
2016-07-25 16:59:52 +08:00
|
|
|
code = 1
|
|
|
|
|
|
|
|
message = {status: code, message: e.message }.to_json
|
|
|
|
|
2016-04-08 14:42:23 +08:00
|
|
|
Rails.logger.error e.inspect
|
2016-04-08 14:50:49 +08:00
|
|
|
Rails.logger.error e.backtrace.join("\n")
|
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
|
2014-12-15 14:06:00 +08:00
|
|
|
end
|