application controller: catch more common exceptions.
This commit is contained in:
@@ -78,11 +78,14 @@ class ApplicationController < ActionController::Base
|
|||||||
case exception
|
case exception
|
||||||
when ActiveRecord::QueryCanceled
|
when ActiveRecord::QueryCanceled
|
||||||
render_error_page(500, exception, message: "The database timed out running your query.")
|
render_error_page(500, exception, message: "The database timed out running your query.")
|
||||||
|
when ActionController::BadRequest
|
||||||
|
render_error_page(400, exception, expected: true)
|
||||||
when ActiveRecord::RecordNotFound
|
when ActiveRecord::RecordNotFound
|
||||||
render_error_page(404, exception, message: "That record was not found", expected: true)
|
render_error_page(404, exception, message: "That record was not found", expected: true)
|
||||||
when ActionController::UnknownFormat
|
when ActionController::RoutingError
|
||||||
@error_message = "#{request.format.to_s} is not a supported format for this page."
|
render_error_page(405, exception, expected: true)
|
||||||
render "static/error.html", status: 406
|
when ActionController::UnknownFormat, ActionView::MissingTemplate
|
||||||
|
render_error_page(406, exception, message: "#{request.format.to_s} is not a supported format for this page", html: true, expected: true)
|
||||||
when Danbooru::Paginator::PaginationError
|
when Danbooru::Paginator::PaginationError
|
||||||
render_error_page(410, exception, expected: true)
|
render_error_page(410, exception, expected: true)
|
||||||
when NotImplementedError
|
when NotImplementedError
|
||||||
@@ -94,15 +97,15 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_error_page(status, exception, message: exception.message, expected: false)
|
def render_error_page(status, exception, message: exception.message, html: false, expected: false)
|
||||||
@error_message = message
|
@error_message = message
|
||||||
|
|
||||||
DanbooruLogger.log(exception, expected: expected)
|
DanbooruLogger.log(exception, expected: expected)
|
||||||
|
|
||||||
if request.format.symbol.in?(%i[html json xml js atom])
|
if html || !request.format.symbol.in?(%i[html json xml js atom])
|
||||||
render template: "static/error", status: status
|
|
||||||
else
|
|
||||||
render template: "static/error.html", status: status
|
render template: "static/error.html", status: status
|
||||||
|
else
|
||||||
|
render template: "static/error", status: status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user