Render error pages using our own templates (#9455)
parent
b7696a6c5c
commit
b75fbcfc4e
@ -0,0 +1,25 @@ |
||||
class ErrorsController < ::ActionController::Base |
||||
include ErrorsHelper |
||||
include OpenProjectErrorHelper |
||||
include Accounts::CurrentUser |
||||
|
||||
def not_found |
||||
render_404 |
||||
end |
||||
|
||||
def unacceptable |
||||
render file: "#{Rails.root}/public/422.html", |
||||
status: :unacceptable, |
||||
layout: false |
||||
end |
||||
|
||||
def internal_error |
||||
render_500 |
||||
end |
||||
|
||||
private |
||||
|
||||
def use_layout |
||||
'only_logo' |
||||
end |
||||
end |
@ -0,0 +1,53 @@ |
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> |
||||
<meta name="viewport" content="width=device-width"> |
||||
<%= output_title_and_meta_tags %> |
||||
<%= sentry_frontend_tags %> |
||||
|
||||
<% relative_url_root = OpenProject::Configuration['rails_relative_url_root'] || '' %> |
||||
<meta name="app_base_path" content="<%= relative_url_root %>"/> |
||||
<base href="<%= relative_url_root %>/" /> |
||||
<% if @project %> |
||||
<meta name="current_project" |
||||
data-project-name="<%= h @project.name %>" |
||||
data-project-id="<%= @project.id %>" |
||||
data-project-identifier="<%= @project.identifier %>"/> |
||||
<% end %> |
||||
<% unless User.current.anonymous? %> |
||||
<meta name="current_user" |
||||
data-name="<%= User.current.name %>" |
||||
data-mail="<%= User.current.mail %>" |
||||
data-id="<%= User.current.id %>" /> |
||||
<% end %> |
||||
|
||||
<% if Setting.demo_projects_available %><meta name="demo_projects_available" content="true"/><% end %> |
||||
<% if Setting.boards_demo_data_available %><meta name="boards_demo_data_available" content="true"/><% end %> |
||||
<%= csrf_meta_tags %> |
||||
<%= initializer_meta_tag %> |
||||
|
||||
<!-- global meta hooks before any scripts are loaded--> |
||||
<%= call_hook :view_layouts_base_html_meta %> |
||||
|
||||
<%= render 'common/favicons' %> |
||||
|
||||
<%# Include CLI assets (development) or prod build assets %> |
||||
<%= include_frontend_assets %> |
||||
|
||||
<%# Render CSS highlighting %> |
||||
<%= stylesheet_link_tag "/highlighting/styles/#{highlight_css_version_tag}", |
||||
media: :all, |
||||
skip_pipeline: true %> |
||||
|
||||
<%# Custom styles %> |
||||
<%= render partial: "custom_styles/inline_css_logo" %> |
||||
<% if apply_custom_styles? %> |
||||
<% cache(CustomStyle.current) do %> |
||||
<%= render partial: "custom_styles/inline_css" %> |
||||
<% if CustomStyle.current.favicon.present? %> |
||||
<link rel="icon" type="image/png" href="<%= custom_style_favicon_path(digest: CustomStyle.current.digest, filename: CustomStyle.current.favicon_identifier) %>" sizes="32x32"> |
||||
<% end %> |
||||
<% if CustomStyle.current.touch_icon.present? %> |
||||
<link rel="apple-touch-icon" sizes="180x180" href="<%= custom_style_touch_icon_path(digest: CustomStyle.current.digest, filename: CustomStyle.current.touch_icon_identifier) %>"> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<%= crowdin_in_context_translation %> |
@ -1,52 +0,0 @@ |
||||
<!---- copyright |
||||
OpenProject is a project management system. |
||||
Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License version 3. |
||||
|
||||
OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
Copyright (C) 2010-2013 the ChiliProject Team |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
This program 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 General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; if not, write to the Free Software |
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
See doc/COPYRIGHT.rdoc for more details. |
||||
|
||||
++--> |
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
||||
"http://www.w3.org/TR/html4/loose.dtd"> |
||||
<html> |
||||
<title>OpenProject 404 error</title> |
||||
<style> |
||||
body{ |
||||
font-family: Trebuchet MS,Georgia,"Times New Roman",serif; |
||||
color:#303030; |
||||
margin:10px; |
||||
} |
||||
h1{ |
||||
font-size:1.5em; |
||||
} |
||||
p{ |
||||
font-size:0.8em; |
||||
} |
||||
</style> |
||||
<body> |
||||
<h1>Page not found</h1> |
||||
<p>The page you were trying to access doesn't exist or has been removed.</p> |
||||
<p><a href="javascript:history.back()">Back</a></p> |
||||
</body> |
||||
</html> |
@ -1,55 +0,0 @@ |
||||
<!---- copyright |
||||
OpenProject is a project management system. |
||||
Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License version 3. |
||||
|
||||
OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
Copyright (C) 2010-2013 the ChiliProject Team |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
This program 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 General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; if not, write to the Free Software |
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
See doc/COPYRIGHT.rdoc for more details. |
||||
|
||||
++--> |
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
||||
"http://www.w3.org/TR/html4/loose.dtd"> |
||||
<html> |
||||
<title>OpenProject 500 error</title> |
||||
<style> |
||||
body{ |
||||
font-family: Trebuchet MS,Georgia,"Times New Roman",serif; |
||||
color:#303030; |
||||
margin:10px; |
||||
} |
||||
h1{ |
||||
font-size:1.5em; |
||||
} |
||||
p{ |
||||
font-size:0.8em; |
||||
} |
||||
</style> |
||||
<body> |
||||
<h1>Internal error</h1> |
||||
<p>An error occurred on the page you were trying to access.<br /> |
||||
If you continue to experience problems please contact your OpenProject administrator for assistance.</p> |
||||
|
||||
<p>If you are the OpenProject administrator, check your log files for details about the error.</p> |
||||
<p><a href="javascript:history.back()">Back</a></p> |
||||
</body> |
||||
</html> |
@ -0,0 +1,28 @@ |
||||
require 'spec_helper' |
||||
|
||||
describe 'Errors handling', type: :feature do |
||||
it 'renders the internal error page in case of exceptions' do |
||||
# We unfortunately cannot test raising exceptions as the test environment |
||||
# marks all requests as local and thus shows exception details instead (like in dev mode) |
||||
visit '/500' |
||||
expect(page).to have_current_path '/500' |
||||
expect(page).to have_text "An error occurred on the page you were trying to access." |
||||
expect(page).to have_no_text "Oh no, this is an internal error!" |
||||
end |
||||
|
||||
it 'renders the not found page' do |
||||
# We unfortunately cannot test raising exceptions as the test environment |
||||
# marks all requests as local and thus shows exception details instead (like in dev mode) |
||||
visit '/404' |
||||
expect(page).to have_current_path '/404' |
||||
expect(page).to have_text "[Error 404] The page you were trying to access doesn't exist or has been removed." |
||||
end |
||||
|
||||
it 'renders the unacceptable response' do |
||||
# This file exists in public and is recommended to be rendered, but I'm not aware |
||||
# of any path that would trigger this |
||||
visit '/422' |
||||
expect(page).to have_current_path '/422' |
||||
expect(page).to have_text 'The change you wanted was rejected.' |
||||
end |
||||
end |
@ -0,0 +1,35 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program 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 General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe 'errors routing', type: :routing do |
||||
it { is_expected.to route(:get, '/404').to(controller: 'errors', action: 'not_found') } |
||||
it { is_expected.to route(:get, '/422').to(controller: 'errors', action: 'unacceptable') } |
||||
it { is_expected.to route(:get, '/500').to(controller: 'errors', action: 'internal_error') } |
||||
end |
Loading…
Reference in new issue