Diff
Modified: trunk/app/controllers/application_controller.rb (3458 => 3459)
--- trunk/app/controllers/application_controller.rb 2013-03-01 15:06:35 UTC (rev 3458)
+++ trunk/app/controllers/application_controller.rb 2013-03-01 15:56:34 UTC (rev 3459)
@@ -488,4 +488,46 @@
format.html { redirect_to target, (referrer.blank? ? nil : params) }
end
end
+
+ # Intercept 404/500 etc. errors and display a custom page
+ def render_optional_error_file(status_code)
+ if status_code == :unauthorized
+ render_401
+ elsif status_code == :not_found
+ render_404
+ elsif status_code == :internal_server_error
+ render_500
+ else
+ super
+ end
+ end
+
+ def render_401(message = nil)
+ @message = message
+ respond_to do |format|
+ format.html { render :template => "errors/401", :status => 401 }
+ format.xml do
+ headers["WWW-Authenticate"] = %(Basic realm="Web Password")
+ render :nothing => true, :status => 401
+ end
+ format.all { render :nothing => true, :status => 401 }
+ end
+ end
+
+ def render_404(message = nil)
+ @message = message
+ respond_to do |format|
+ format.html { render :template => "errors/404", :status => 404 }
+ format.all { render :nothing => true, :status => 404 }
+ end
+ end
+
+ def render_500(message = nil)
+ @message = message
+ respond_to do |format|
+ format.html { render :template => "errors/500", :status => 500 }
+ format.all { render :nothing => true, :status => 500 }
+ end
+ end
+
end
Modified: trunk/app/controllers/blobs_controller.rb (3458 => 3459)
--- trunk/app/controllers/blobs_controller.rb 2013-03-01 15:06:35 UTC (rev 3458)
+++ trunk/app/controllers/blobs_controller.rb 2013-03-01 15:56:34 UTC (rev 3459)
@@ -427,13 +427,13 @@
else
if logged_in?
- error("File not found (id not authorized)", "is invalid (not authorized)")
+ render_401("You are not authorized to access this file.")
else
find_blob_auth if login_required
end
end
rescue ActiveRecord::RecordNotFound
- error("File not found", "is invalid")
+ render_404("File not found.")
end
end
@@ -461,7 +461,7 @@
def check_is_owner
if @blob
- error("You are not authorised to manage this File", "") unless @blob.owner?(current_user)
+ render_401("You are not authorised to manage this file.") unless @blob.owner?(current_user)
end
end
Modified: trunk/app/controllers/packs_controller.rb (3458 => 3459)
--- trunk/app/controllers/packs_controller.rb 2013-03-01 15:06:35 UTC (rev 3458)
+++ trunk/app/controllers/packs_controller.rb 2013-03-01 15:56:34 UTC (rev 3459)
@@ -479,10 +479,10 @@
@base_host = base_host
else
- error("You are not authorised to perform this action", "is not authorized")
+ render_401("You are not authorized to access this pack.")
end
rescue ActiveRecord::RecordNotFound
- error("Pack not found", "is invalid")
+ render_404("Pack not found.")
end
end
Modified: trunk/app/controllers/workflows_controller.rb (3458 => 3459)
--- trunk/app/controllers/workflows_controller.rb 2013-03-01 15:06:35 UTC (rev 3458)
+++ trunk/app/controllers/workflows_controller.rb 2013-03-01 15:56:34 UTC (rev 3459)
@@ -623,7 +623,7 @@
if params[:version]
if @workflow.find_version(params[:version]) == false
- error("Version not found (is invalid)", "not found (is invalid)", :version)
+ render_404("Workflow version not found.")
end
if @workflow.versions.length < 2
error("Can't delete all versions", " is not allowed", :version)
@@ -756,7 +756,7 @@
@viewing_version_number = params[:version].to_i
@viewing_version = viewing
else
- error("Workflow version not found (possibly has been deleted)", "not found (is invalid)", :version)
+ render_404("Workflow version not found.")
end
else
@viewing_version_number = @latest_version_number
@@ -791,13 +791,10 @@
logger.debug("@viewing_version_number = address@hidden")
logger.debug("@workflow.image != nil = address@hidden != nil}")
else
- error("Workflow #{params[:id]} not accessible, you are not authorized",
- "not accessible (not authorized)", :id, 401)
- return false
+ render_401("You are not authorized to access this workflow.")
end
rescue ActiveRecord::RecordNotFound
- error("Workflow not found", "is invalid")
- return false
+ render_404("Workflow not found.")
end
end
@@ -909,7 +906,7 @@
def check_is_owner
if @workflow
- error("You are not authorised to manage this Workflow", "") unless @workflow.owner?(current_user)
+ render_401("You are not authorized to manage this workflow.") unless @workflow.owner?(current_user)
end
end
@@ -937,16 +934,12 @@
end
end
- def error(notice, message, attr=:id, status=nil)
+ def error(notice, message, attr=:id)
flash[:error] = notice
(err = Workflow.new.errors).add(attr, message)
respond_to do |format|
format.html { redirect_to workflows_url }
- format.xml do
- headers["WWW-Authenticate"] = %(Basic realm="Web Password") if status == 401
- render :text => notice, :status => status
- end
end
end
Added: trunk/app/views/errors/401.html.erb (0 => 3459)
--- trunk/app/views/errors/401.html.erb (rev 0)
+++ trunk/app/views/errors/401.html.erb 2013-03-01 15:56:34 UTC (rev 3459)
@@ -0,0 +1,12 @@
+<div class="error">
+ <h1>401 - Unauthorized</h1>
+ <% if @message %>
+ <%= @message %>
+ <% else %>
+ You do not have sufficient privileges to view this page.
+ <% end %>
+ <br/><br/>
+ <% unless logged_in? %>
+ If you have registered an account, please log in and try again.
+ <% end %>
+</div>
\ No newline at end of file
Added: trunk/app/views/errors/404.html.erb (0 => 3459)
--- trunk/app/views/errors/404.html.erb (rev 0)
+++ trunk/app/views/errors/404.html.erb 2013-03-01 15:56:34 UTC (rev 3459)
@@ -0,0 +1,16 @@
+<div class="error">
+ <h1>404 - Not Found</h1>
+ <% if @message %>
+ <%= @message %>
+ <% else %>
+ The page you were looking for could not be found.
+ <% end %>
+
+ <% unless request.referer.blank? %>
+ <br/>
+ <br/>
+ <%= link_to 'Report broken link',
+ '/feedback?' + {:subject=>'Broken link',
+ :content=>"Broken link #{request.request_uri} on #{request.referer}"}.to_param %>
+ <% end %>
+</div>
\ No newline at end of file
Added: trunk/app/views/errors/500.html.erb (0 => 3459)
--- trunk/app/views/errors/500.html.erb (rev 0)
+++ trunk/app/views/errors/500.html.erb 2013-03-01 15:56:34 UTC (rev 3459)
@@ -0,0 +1,5 @@
+<div class="error">
+ <h1>500 - Internal Server Error</h1>
+ The server encountered an error whilst processing your request.<br/><br/>
+ The administrators have been notified of this problem.
+</div>
\ No newline at end of file
Modified: trunk/app/views/layouts/_breadcrumbs_bar.rhtml (3458 => 3459)
--- trunk/app/views/layouts/_breadcrumbs_bar.rhtml 2013-03-01 15:06:35 UTC (rev 3458)
+++ trunk/app/views/layouts/_breadcrumbs_bar.rhtml 2013-03-01 15:56:34 UTC (rev 3459)
@@ -3,7 +3,8 @@
<td>
<ul class="breadcrumb_list">
<li><%= link_to "Home", home_url %></li>
- <%= render :partial => "breadcrumbs" %>
+ <% # no better way to check for breadcrumbs partial... %>
+ <%= render :partial => "breadcrumbs" rescue nil %>
</ul>
</td>
<td style="text-align: right; padding-left: 1em;">
Modified: trunk/public/stylesheets/styles.css (3458 => 3459)
--- trunk/public/stylesheets/styles.css 2013-03-01 15:06:35 UTC (rev 3458)
+++ trunk/public/stylesheets/styles.css 2013-03-01 15:56:34 UTC (rev 3459)
@@ -2403,3 +2403,17 @@
color: #333333;
font-size: 100%;
}
+
+div.error {
+ width: 500px;
+ border: 2px solid #f44;
+ padding-bottom: 1em;
+ margin: 1em auto;
+ text-align: center;
+}
+
+div.error h1 {
+ color: white;
+ background-color: #f44;
+ margin-top: 0;
+}