module Lanes::API::ErrorFormmater
Public Instance Methods
call(message, backtrace=nil, options=nil, env=nil)
click to toggle source
# File lib/lanes/api/error_formatter.rb, line 6 def call(message, backtrace=nil, options=nil, env=nil) { success: false, message: message, errors: { base: message } }.to_json end
handle_exception(message, code, e)
click to toggle source
# File lib/lanes/api/error_formatter.rb, line 13 def handle_exception(message, code, e) Rack::Response.new([self.call(message)], code, {"Content-type" => "application/json"} ).finish Lanes.logger.error e end
handle_fk_exception(e,model)
click to toggle source
# File lib/lanes/api/error_formatter.rb, line 20 def handle_fk_exception(e,model) ( target, depends ) = e.message.scan(/on table \"(.*?)\"/).flatten.map do |table| table.gsub(/^hip_/, '').capitalize.singularize end Lanes::API::ErrorFormmater.handle_exception( "Unable to delete #{target}, still in use by #{depends}", 400, e ) end
handle_not_found_exception(e,model)
click to toggle source
# File lib/lanes/api/error_formatter.rb, line 29 def handle_not_found_exception(e,model) Lanes::API::ErrorFormmater.handle_exception( model.to_s.demodulize + " (or one of it's dependencies) was not found", 404, e ) end