Module: Hippo::API::ErrorFormmater
- Extended by:
- ErrorFormmater
- Included in:
- ErrorFormmater
- Defined in:
- lib/hippo/api/error_formatter.rb
Instance Method Summary collapse
- #call(message, backtrace = nil, options = nil, env = nil) ⇒ Object
- #handle_exception(message, code, e) ⇒ Object
- #handle_fk_exception(e, model) ⇒ Object
- #handle_not_found_exception(e, model) ⇒ Object
Instance Method Details
#call(message, backtrace = nil, options = nil, env = nil) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/hippo/api/error_formatter.rb', line 6 def call(, backtrace=nil, =nil, env=nil) { success: false, message: , errors: { base: } }.to_json end |
#handle_exception(message, code, e) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/hippo/api/error_formatter.rb', line 13 def handle_exception(, code, e) Rack::Response.new([self.call()], code, {"Content-type" => "application/json"} ).finish Hippo.logger.error e end |
#handle_fk_exception(e, model) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/hippo/api/error_formatter.rb', line 20 def handle_fk_exception(e,model) ( target, depends ) = e..scan(/on table \"(.*?)\"/).flatten.map do |table| table.gsub(/^hip_/, '').capitalize.singularize end Hippo::API::ErrorFormmater.handle_exception( "Unable to delete #{target}, still in use by #{depends}", 400, e ) end |
#handle_not_found_exception(e, model) ⇒ Object
29 30 31 32 33 |
# File 'lib/hippo/api/error_formatter.rb', line 29 def handle_not_found_exception(e,model) Hippo::API::ErrorFormmater.handle_exception( model.to_s.demodulize + " (or one of it's dependencies) was not found", 404, e ) end |