favorites: fix error handling.
* Return HTTP 422 instead of HTTP 500 on "You have already favorited this post" errors. * Log unexpected errors in Ajax requests to the console.
This commit is contained in:
@@ -26,6 +26,12 @@ class ApplicationController < ActionController::Base
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def self.rescue_with(*klasses, status: 500)
|
||||||
|
rescue_from *klasses do |exception|
|
||||||
|
render_error_page(status, exception)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def show_moderation_notice?
|
def show_moderation_notice?
|
||||||
CurrentUser.can_approve_posts? && (cookies[:moderated].blank? || Time.at(cookies[:moderated].to_i) < 20.hours.ago)
|
CurrentUser.can_approve_posts? && (cookies[:moderated].blank? || Time.at(cookies[:moderated].to_i) < 20.hours.ago)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ class FavoritesController < ApplicationController
|
|||||||
before_action :member_only, except: [:index]
|
before_action :member_only, except: [:index]
|
||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
skip_before_action :api_check
|
skip_before_action :api_check
|
||||||
|
rescue_with Favorite::Error, status: 422
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if params[:tags]
|
if params[:tags]
|
||||||
|
|||||||
@@ -1,2 +1,10 @@
|
|||||||
|
var klass = <%= raw @exception.class.to_s.to_json %>;
|
||||||
var message = <%= raw @message.to_json %>;
|
var message = <%= raw @message.to_json %>;
|
||||||
Danbooru.Utility.error(message);
|
var backtrace = <%= raw @backtrace.to_json %>;
|
||||||
|
|
||||||
|
<% if @expected %>
|
||||||
|
Danbooru.Utility.error(message);
|
||||||
|
<% else %>
|
||||||
|
console.error(klass, message, backtrace);
|
||||||
|
Danbooru.Utility.error(message);
|
||||||
|
<% end %>
|
||||||
|
|||||||
Reference in New Issue
Block a user