Skip to content

Commit

Permalink
Unify error pages (bigbluebutton#674)
Browse files Browse the repository at this point in the history
* Unify error pages

* Start travis
  • Loading branch information
shawn-higgins1 authored and jfederico committed Jul 22, 2019
1 parent 9dd3013 commit ee26036
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 82 deletions.
13 changes: 9 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def default_meeting_options

# Manually deal with 401 errors
rescue_from CanCan::AccessDenied do |_exception|
render "errors/not_found"
render "errors/greenlight_error"
end

# Checks to make sure that the admin has changed his password from the default
Expand Down Expand Up @@ -141,13 +141,18 @@ def set_user_domain
retrieve_provider_info(@user_domain, 'api2', 'getUserGreenlightCredentials')
rescue => e
if e.message.eql? "No user with that id exists"
render "errors/not_found", locals: { message: I18n.t("errors.not_found.user_not_found.message"),
render "errors/greenlight_error", locals: { message: I18n.t("errors.not_found.user_not_found.message"),
help: I18n.t("errors.not_found.user_not_found.help") }
elsif e.message.eql? "Provider not included."
render "errors/not_found", locals: { message: I18n.t("errors.not_found.user_missing.message"),
render "errors/greenlight_error", locals: { message: I18n.t("errors.not_found.user_missing.message"),
help: I18n.t("errors.not_found.user_missing.help") }
elsif e.message.eql? "That user has no configured provider."
render "errors/greenlight_error", locals: { status_code: 501,
message: I18n.t("errors.no_provider.message"),
help: I18n.t("errors.no_provider.help") }
else
render "errors/internal_error"
render "errors/greenlight_error", locals: { status_code: 500, message: I18n.t("errors.internal.message"),
help: I18n.t("errors.internal.help"), display_back: true }
end
end
end
Expand Down
13 changes: 10 additions & 3 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@

class ErrorsController < ApplicationController
def not_found
render status: 404, formats: :html
render "greenlight_error", status: 404, formats: :html
end

def internal_error
render status: 500, formats: :html
render "errors/greenlight_error", status: 500, formats: :html,
locals: {
status_code: 500,
message: I18n.t("errors.internal.message"),
help: I18n.t("errors.internal.help"),
display_back: true
}
end

def unauthorized
render status: 401, formats: :html
render "errors/greenlight_error", status: 401, formats: :html, locals: { status_code: 401,
message: I18n.t("errors.unauthorized.message"), help: I18n.t("errors.unauthorized.help"), display_back: true }
end
end
39 changes: 39 additions & 0 deletions app/views/errors/greenlight_error.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<%
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
%>

<div class="container text-center pt-9">
<div class="display-1 text-primary mb-5">
<% if defined?(status_code) %>
<%= status_code %>
<% else %>
404
<% end %>
</div>
<% if defined?(message) && defined?(help) %>
<h1 class="h2 mb-3"><%= message %></h1>
<p class="h4 text-muted font-weight-normal mb-7"><%= help %></p>
<% if defined?(display_back) && display_back %>
<a class="btn btn-primary" href="javascript:history.back()">
<i class="fas fa-arrow-left mr-2"></i><%= t("go_back") %>
</a>
<% end %>
<% else %>
<h1 class="h2 mb-3"><%= t("errors.not_found.message") %></h1>
<p class="h4 text-muted font-weight-normal mb-7"><%= t("errors.not_found.help") %></p>
<a class="btn btn-primary" href="javascript:history.back()">
<i class="fas fa-arrow-left mr-2"></i><%= t("go_back") %>
</a>
<% end %>
</div>
23 changes: 0 additions & 23 deletions app/views/errors/internal_error.html.erb

This file was deleted.

28 changes: 0 additions & 28 deletions app/views/errors/not_found.html.erb

This file was deleted.

20 changes: 0 additions & 20 deletions app/views/errors/unauthorized.html.erb

This file was deleted.

3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ en:
accepted: must be accepted
confirmation: doesn't match %{attribute}
inclusion: is not included in the list
no_provider:
message: The customer you provided doesn't have Greenlight configured
help: Please contact Blindside Networks to setup Greenlight
not_found:
message: Sorry! The page you are looking for does not exist.
help: Is it possible its been removed?
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admins_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@request.session[:user_id] = @user.id
get :index

expect(response).to render_template(:not_found)
expect(response).to render_template(:greenlight_error)
end

it "renders the admin settings if an admin tries to acccess it" do
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def user_not_found
routes.draw { get "user_not_found" => "anonymous#user_not_found" }

get :user_not_found
expect(response).to render_template("errors/not_found")
expect(response).to render_template("errors/greenlight_error")
end

it "renders a 404 error if user is not given" do
Expand All @@ -92,7 +92,7 @@ def user_not_found
routes.draw { get "user_not_found" => "anonymous#user_not_found" }

get :user_not_found
expect(response).to render_template("errors/not_found")
expect(response).to render_template("errors/greenlight_error")
end

it "renders a 500 error if any other error related to bbb api" do
Expand All @@ -104,7 +104,7 @@ def user_not_found
routes.draw { get "user_not_found" => "anonymous#user_not_found" }

get :user_not_found
expect(response).to render_template("errors/internal_error")
expect(response).to render_template("errors/greenlight_error")
end
end
end

0 comments on commit ee26036

Please sign in to comment.