unified error handling system
This commit is contained in:
@@ -14,12 +14,12 @@ class ApplicationController < ActionController::Base
|
||||
protected
|
||||
def rescue_exception(exception)
|
||||
@exception = exception
|
||||
render :action => "static/error", :status => 500
|
||||
render :template => "static/error", :status => 500
|
||||
end
|
||||
|
||||
def render_pagination_limit
|
||||
@error_message = "You can view up to 1,000 pages. Please narrow your search terms."
|
||||
render :action => "static/error", :status => 410
|
||||
@error_message = "You can only view up to #{Danbooru.config.max_numbered_pages} pages. Please narrow your search terms."
|
||||
render :template => "static/error", :status => 410
|
||||
end
|
||||
|
||||
def access_denied
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class LegacyController < ApplicationController
|
||||
before_filter :member_only, :only => [:create_post]
|
||||
rescue_from PostSets::SearchError, :with => :error
|
||||
rescue_from PostSets::SearchError, :with => :rescue_exception
|
||||
|
||||
def posts
|
||||
@post_set = PostSets::Post.new(tag_query, params[:page], params[:limit])
|
||||
@@ -31,9 +31,6 @@ class LegacyController < ApplicationController
|
||||
def unavailable
|
||||
render :text => "this resource is no longer available", :status => 410
|
||||
end
|
||||
|
||||
def error
|
||||
end
|
||||
|
||||
private
|
||||
def tag_query
|
||||
|
||||
@@ -2,4 +2,7 @@ class StaticController < ApplicationController
|
||||
def terms_of_service
|
||||
render :layout => "blank"
|
||||
end
|
||||
|
||||
def error
|
||||
end
|
||||
end
|
||||
|
||||
1
app/views/legacy/tags.json.erb
Normal file
1
app/views/legacy/tags.json.erb
Normal file
@@ -0,0 +1 @@
|
||||
[<%= @tags.map {|x| x.to_legacy_json}.join(", ").html_safe %>]
|
||||
@@ -1 +0,0 @@
|
||||
{success: false, message: "<%= @exception.to_s %>"}
|
||||
@@ -1,2 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<result success="false"><%= @exception.to_s %></result>
|
||||
0
app/views/static/error.atom.erb
Normal file
0
app/views/static/error.atom.erb
Normal file
5
app/views/static/error.json.erb
Normal file
5
app/views/static/error.json.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<% if @error_message %>
|
||||
{success: false, message: <%= raw @error_message.to_json %>}
|
||||
<% else %>
|
||||
{success: false, message: <%= raw @exception.to_s.to_json %>}
|
||||
<% end %>
|
||||
6
app/views/static/error.xml.erb
Normal file
6
app/views/static/error.xml.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<% if @error_message %>
|
||||
<result success="false"><%= @error_message %></result>
|
||||
<% else %>
|
||||
<result success="false"><%= @exception.to_s %></result>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user