Sha256: 97aa29782a7b80e0542d60e4e229cb4bbeeb1bb7889950eaf8c487f55bf00952
Contents?: true
Size: 1.9 KB
Versions: 23
Compression:
Stored size: 1.9 KB
Contents
class Fanforce::Plugin::Sinatra set :raise_errors, false set :show_exceptions, false error 400..600 do e = env['sinatra.error'] or (next response if e.nil?) if Object.const_defined?('Fanforce') and Fanforce.const_defined?('API') and e.is_a?(Fanforce::API::Error) errors = e.errors else errors = [{message: 'There has been an internal server error. Our developers have been notified.'}] end message = errors[0][:message] show_error_details = params[:show_error_details] || Fanforce::Plugin.config.show_error_details admin_details = fetch_admin_details(e, errors) Bugsnag.notify(e, admin_details.merge(plugin_id: Fanforce::Plugin.plugin_id)) if Fanforce::Plugin.is_bugsnag_enabled? body = {errors: message} body.merge!(admin_details.merge(backtrace: e.backtrace)).delete(:public_response) if show_error_details status(e.respond_to?(:code ) ? e.code : 500) if show_error_details == 'text' response.headers['Content-Type'] = 'text/plain' format_as_text(body) else json(body) end end def format_as_text(body) text = "--------------------------------------------------------------------------------------------------------\n" text += "ERROR: #{body[:raw_message]}\n" text += "CLASS: #{body[:error_class]}\n" if body[:error_class] text += "\nCURL COMMAND: #{body[:curl_command]}\n" if body[:curl_command] text += "\nBACKTRACE:\n#{body[:backtrace].join("\n")}\n" if body[:backtrace] text += "--------------------------------------------------------------------------------------------------------\n" end def fetch_admin_details(e, errors=[], additional_options={}) admin_details = {error_class: e.class.name, public_response: errors} admin_details[:curl_command] = e.curl_command if e.respond_to?(:curl_command) admin_details[:raw_message] = e.message admin_details.merge(additional_options) end end
Version data entries
23 entries across 23 versions & 1 rubygems