forked from e621ng/e621ng
Minor adjustments to error reporting, remove js response
This commit is contained in:
parent
36af053218
commit
8e2dc40e12
@ -59,14 +59,6 @@ class ApplicationController < ActionController::Base
|
||||
puts "---"
|
||||
end
|
||||
|
||||
ExceptionLog.add(exception, CurrentUser.ip_addr, {
|
||||
host: Socket.gethostname,
|
||||
params: params,
|
||||
user_id: CurrentUser.id,
|
||||
referrer: request.referrer,
|
||||
user_agent: request.user_agent
|
||||
})
|
||||
|
||||
case exception
|
||||
when APIThrottled
|
||||
render_error_page(429, exception, message: "Too many requests")
|
||||
@ -97,17 +89,32 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
end
|
||||
|
||||
def render_404
|
||||
render "static/404", formats: [:html, :json, :atom]
|
||||
end
|
||||
|
||||
def render_error_page(status, exception, message: exception.message, format: request.format.symbol)
|
||||
@exception = exception
|
||||
@expected = status < 500
|
||||
@message = message.encode("utf-8", { invalid: :replace, undef: :replace })
|
||||
@backtrace = Rails.backtrace_cleaner.clean(@exception.backtrace)
|
||||
format = :html unless format.in?(%i[html json js atom])
|
||||
format = :html unless format.in?(%i[html json atom])
|
||||
|
||||
# if InvalidAuthenticityToken was raised, CurrentUser isn't set so we have to use the blank layout.
|
||||
layout = CurrentUser.user.present? ? "default" : "blank"
|
||||
if !CurrentUser.user&.try(:is_janitor?)
|
||||
@message = "An unexpected error occurred."
|
||||
end
|
||||
|
||||
DanbooruLogger.log(@exception, expected: @expected)
|
||||
log = ExceptionLog.add(exception, CurrentUser.ip_addr, {
|
||||
host: Socket.gethostname,
|
||||
params: params,
|
||||
user_id: CurrentUser.id,
|
||||
referrer: request.referrer,
|
||||
user_agent: request.user_agent
|
||||
})
|
||||
@log_code = log&.code
|
||||
render "static/error", layout: layout, status: status, formats: format
|
||||
end
|
||||
|
||||
@ -131,9 +138,6 @@ class ApplicationController < ActionController::Base
|
||||
fmt.json do
|
||||
render :json => {:success => false, reason: @message}.to_json, :status => 403
|
||||
end
|
||||
fmt.js do
|
||||
render js: "", :status => 403
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -15,7 +15,7 @@ class DanbooruLogger
|
||||
Rails.logger.error("#{exception.class}: #{exception.message}\n#{backtrace}")
|
||||
end
|
||||
|
||||
if defined?(::NewRelic)
|
||||
if defined?(::NewRelic) && !expected
|
||||
::NewRelic::Agent.notice_error(exception, expected: expected, custom_params: params)
|
||||
end
|
||||
end
|
||||
|
1
app/views/static/404.html.erb
Normal file
1
app/views/static/404.html.erb
Normal file
@ -0,0 +1 @@
|
||||
<p>Not found.</p>
|
5
app/views/static/404.json.erb
Normal file
5
app/views/static/404.json.erb
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"success": false,
|
||||
"message": "Not found.",
|
||||
"code": null
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
<%= render "static/backtrace", backtrace: @exception.backtrace %>
|
||||
<% elsif @message %>
|
||||
<p><%= @message %></p>
|
||||
<p>Log ID: <%= @log_code || '(none)' %></p>
|
||||
<% else %>
|
||||
<p>An error happened but there are no details provided. That's pretty odd.</p>
|
||||
<% end %>
|
||||
|
@ -1,2 +0,0 @@
|
||||
var message = <%= raw @message.to_json %>;
|
||||
Danbooru.Utility.error(message);
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"success": false,
|
||||
"message": <%= raw @message.to_json %>,
|
||||
"backtrace": <%= raw @backtrace.to_json %>
|
||||
"code": <%= raw @log_code.to_json %>
|
||||
}
|
||||
|
@ -1,2 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<result success="false"><%= @message %></result>
|
Loading…
Reference in New Issue
Block a user