Created
September 25, 2018 12:41
-
-
Save apostergiou/c7b31b95eb9f533ab6c1ea6cbf182b68 to your computer and use it in GitHub Desktop.
ruby print backtrace
This file contains 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 characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment