Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ def server_error
def unauthorised
render status: 401, formats: [:html]
end

def unprocessable
render status: 422, formats: [:html]
end
end
14 changes: 14 additions & 0 deletions app/views/errors/unprocessable.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="empty">
<div class="empty-header">422</div>
<p class="empty-title"><%= t "errors.titles.form_update" %></p>
<p class="empty-subtitle text-muted">
<%= t "errors.messages.unprocessable" %>
</p>
<div class="empty-action">
<a href="/" class="btn btn-primary">
<!-- Download SVG icon from http://tabler-icons.io/i/arrow-left -->
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><line x1="5" y1="12" x2="19" y2="12" /><line x1="5" y1="12" x2="11" y2="18" /><line x1="5" y1="12" x2="11" y2="6" /></svg>
<%= t "errors.cta.go_home" %>
</a>
</div>
</div>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ en:
go_home: Go home
messages:
invalid_date_range: The chosen dates are invalid
unprocessable: We couldn't process your request. Please go back and try again.
different_practice: Must belong to this practice
invalid_email_format: Invalid format
unauthorised: You don't have permission to do this
Expand Down
1 change: 1 addition & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ es:
go_home: Ir a la página principal
messages:
invalid_date_range: Las fechas son invalidas.
unprocessable: No pudimos procesar tu solicitud. Por favor regresa e inténtalo de nuevo.
different_practice: Debe pertenecer a esta clínica
invalid_email_format: Formato invalido.
unauthorised: No posees los permisos necesarios para hacer esto.
Expand Down
1 change: 1 addition & 0 deletions config/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ pt:
go_home: Ir para início
messages:
invalid_date_range: As datas escolhidas são inválidas
unprocessable: Não conseguimos processar sua solicitação. Por favor, volte e tente novamente.
different_practice: Deve pertencer a esta clínica
invalid_email_format: Formato inválido
unauthorised: Você não tem permissão para fazer isso
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
# error handling
get '/404', to: 'errors#not_found'
get '/401', to: 'errors#unauthorised'
get '/422', to: 'errors#server_error'
get '/422', to: 'errors#unprocessable'
get '/500', to: 'errors#server_error'

root to: 'welcome#index'
Expand Down
29 changes: 29 additions & 0 deletions test/functional/errors_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require 'test_helper'

class ErrorsControllerTest < ActionController::TestCase
test '/422 routes to the unprocessable page' do
assert_routing '/422', controller: 'errors', action: 'unprocessable'
end

test 'unprocessable renders with a 422 status' do
get :unprocessable
assert_response :unprocessable_entity
end

test 'not_found renders with a 404 status' do
get :not_found
assert_response :not_found
end

test 'unauthorised renders with a 401 status' do
get :unauthorised
assert_response :unauthorized
end

test 'server_error renders with a 500 status' do
get :server_error
assert_response :internal_server_error
end
end
Loading