Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Api < Grape::API
- class << self
- def log_exception(exception)
- trace = exception.backtrace
- message = "\n#{exception.class} (#{exception.message}):\n"
- message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
- message << " " << trace.join("\n ")
- Rails.logger.error(message)
- end
- end
- rescue_from AuctionsList::RecordNotFound, ActiveRecord::RecordNotFound do |exception|
- Api.log_exception(exception)
- rack_response(MultiJson.dump({ message: '未找到', status: 404, success: false }), 404 )
- end
- rescue_from Grape::Exceptions::ValidationErrors do |exception|
- Api.log_exception(exception)
- rack_response(MultiJson.dump({ message: "#{exception.message}", status: 400, success: false }), 200)
- end
- rescue_from :all do |exception|
- Api.log_exception(exception)
- rack_response(MultiJson.dump({ message: "未知错误", status: 500, success: false }), 200)
- raise exception
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement