Browse Source

Maintenance: Align not found error page output with the agreed design.

Dusan Vuckovic 6 months ago
parent
commit
1dda357558

+ 1 - 1
app/controllers/errors_controller.rb

@@ -3,6 +3,6 @@
 class ErrorsController < ApplicationController
   skip_before_action :verify_csrf_token
   def routing
-    not_found(ActionController::RoutingError.new("No route matches [#{request.method}] #{request.path}"))
+    not_found(ActionController::RoutingError.new("This page doesn't exist.")) # rubocop:disable Zammad/DetectTranslatableString
   end
 end

+ 1 - 1
app/controllers/knowledge_base/public/base_controller.rb

@@ -113,7 +113,7 @@ class KnowledgeBase::Public::BaseController < ApplicationController
                                e
                              else
                                ActionController::RoutingError
-                                 .new "No route matches #{request.path.inspect}"
+                                 .new "This page doesn't exist." # rubocop:disable Zammad/DetectTranslatableString
                              end
 
     logger.error e

+ 3 - 1
public/401.html

@@ -12,7 +12,9 @@
   <div class="error-image" style="background-image: url(/assets/error/error-1.svg)"></div>
   <p>Sorry, but your authentication failed. Double check your credentials and try again.</p>
 <% else %>
-  <div><%= @exception.message %></div>
+  <% if @exception.message != @message %>
+    <div><%= @exception.message %></div>
+  <% end %>
   <% if @exception.backtrace %>
     <pre><code>
 <% @exception.backtrace.each {|row| %>

+ 3 - 1
public/403.html

@@ -12,7 +12,9 @@
   <div class="error-image" style="background-image: url(/assets/error/error-1.svg)"></div>
   <p>Sorry, but you're not allowed to access this page. If you're registered please log in and refresh this page.</p>
 <% else %>
-  <div><%= @exception.message %></div>
+  <% if @exception.message != @message %>
+    <div><%= @exception.message %></div>
+  <% end %>
   <% if @exception.backtrace %>
     <pre><code>
 <% @exception.backtrace.each {|row| %>

+ 3 - 1
public/404.html

@@ -12,7 +12,9 @@
   <div class="error-image" style="background-image: url(/assets/error/error-2.svg)"></div>
   <p>Sorry, but the Phoenix is not able to find your resource. Try checking the URL for errors.</p>
 <% else %>
-  <div><%= @exception.message %></div>
+  <% if @exception.message != @message %>
+    <div><%= @exception.message %></div>
+  <% end %>
   <% if @exception.backtrace %>
     <div>Traceback:</div>
     <% @exception.backtrace.each {|row| %>

+ 3 - 1
public/422.html

@@ -12,7 +12,9 @@
   <div class="error-image" style="background-image: url(/assets/error/error-1.svg)"></div>
   <p>Maybe you tried to change something you didn't have access to.</p>
 <% else %>
-  <div><%= @exception.message %></div>
+  <% if @exception.message != @message %>
+    <div><%= @exception.message %></div>
+  <% end %>
   <% if @exception.backtrace %>
     <div>Traceback:</div>
     <% @exception.backtrace.each {|row| %>

+ 1 - 1
public/500.html

@@ -18,4 +18,4 @@
   <% end %>
 <% end %>
 </body>
-</html>
+</html>

+ 4 - 5
spec/requests/error_spec.rb

@@ -32,7 +32,7 @@ RSpec.describe 'Error handling', type: :request do
     it { expect(response.body).to include('<html') }
     it { expect(response.body).to include("<title>#{title}</title>") }
     it { expect(response.body).to match("<h1[^>]*>#{headline}</h1>") }
-    it { expect(response.body).to include(message) }
+    it { expect(response.body).to include(CGI.escapeHTML(message)) }
   end
 
   context 'URL route does not exist' do
@@ -42,7 +42,7 @@ RSpec.describe 'Error handling', type: :request do
     end
 
     let(:url)         { '/not_existing_url' }
-    let(:message)     { "No route matches [GET] #{url}" }
+    let(:message)     { "This page doesn't exist." }
     let(:http_status) { :not_found }
 
     context 'requesting JSON' do
@@ -57,8 +57,7 @@ RSpec.describe 'Error handling', type: :request do
 
       context 'when request ends with URL' do
 
-        let(:url) { "//////#{message}" }
-        let(:message) { 'this__website__is__closed__visit__our__new__site:_someother.com' }
+        let(:url) { '//////this__website__is__closed__visit__our__new__site:_someother.com' }
 
         include_examples 'HTML response format'
       end
@@ -73,7 +72,7 @@ RSpec.describe 'Error handling', type: :request do
       get '/api/v1/organizations', as: as
     end
 
-    let(:message) { 'Invalid BasicAuth credentials' }
+    let(:message)     { 'Invalid BasicAuth credentials' }
     let(:http_status) { :unauthorized }
 
     context 'requesting JSON' do

+ 1 - 1
spec/requests/knowledge_base_public/answers_spec.rb

@@ -48,7 +48,7 @@ RSpec.describe 'KnowledgeBase public answers', type: :request do
       # https://github.com/zammad/zammad/issues/3888
       it 'returns route not found error' do
         get help_answer_path(locale_name, category, published_answer)
-        expect(response.body).to include('No route matches')
+        expect(response.body).to include(CGI.escapeHTML("This page doesn't exist."))
       end
     end
   end