Created
September 25, 2018 12:41
-
-
Save ay589/c7b31b95eb9f533ab6c1ea6cbf182b68 to your computer and use it in GitHub Desktop.
Revisions
-
ay589 created this gist
Sep 25, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ rescue_from StandardError do |exception| # Handle only JSON requests raise unless request.format.json? err = {error: exception.message} err[:backtrace] = exception.backtrace.select do |line| # filter out non-significant lines: %w(/gems/ /rubygems/ /lib/ruby/).all? do |litter| not line.include?(litter) end end if Rails.env.development? and exception.is_a? Exception # duplicate exception output to console: STDERR.puts ['ERROR:', err[:error], ''] .concat(err[:backtrace] || []).join "\n" render :json => err, :status => 500 end