Handle errors using Gaffe
This commit is contained in:
parent
ae4979a3f0
commit
9efa9d5d43
12 changed files with 71 additions and 17 deletions
1
Gemfile
1
Gemfile
|
@ -46,6 +46,7 @@ gem 'recurring_select'
|
||||||
gem 'roo', '~> 2.0.0'
|
gem 'roo', '~> 2.0.0'
|
||||||
gem 'roo-xls'
|
gem 'roo-xls'
|
||||||
gem 'spreadsheet'
|
gem 'spreadsheet'
|
||||||
|
gem 'gaffe'
|
||||||
|
|
||||||
# we use the git version of acts_as_versioned, and need to include it in this Gemfile
|
# we use the git version of acts_as_versioned, and need to include it in this Gemfile
|
||||||
gem 'acts_as_versioned', github: 'technoweenie/acts_as_versioned'
|
gem 'acts_as_versioned', github: 'technoweenie/acts_as_versioned'
|
||||||
|
|
|
@ -153,6 +153,8 @@ GEM
|
||||||
faker (1.4.3)
|
faker (1.4.3)
|
||||||
i18n (~> 0.5)
|
i18n (~> 0.5)
|
||||||
ffi (1.9.10)
|
ffi (1.9.10)
|
||||||
|
gaffe (1.0.2)
|
||||||
|
rails (>= 3.2.0)
|
||||||
git-version-bump (0.15.1)
|
git-version-bump (0.15.1)
|
||||||
globalid (0.3.5)
|
globalid (0.3.5)
|
||||||
activesupport (>= 4.1.0)
|
activesupport (>= 4.1.0)
|
||||||
|
@ -488,6 +490,7 @@ DEPENDENCIES
|
||||||
faker
|
faker
|
||||||
foodsoft_messages!
|
foodsoft_messages!
|
||||||
foodsoft_wiki!
|
foodsoft_wiki!
|
||||||
|
gaffe
|
||||||
haml-rails
|
haml-rails
|
||||||
i18n-js (~> 3.0.0.rc8)
|
i18n-js (~> 3.0.0.rc8)
|
||||||
i18n-spec
|
i18n-spec
|
||||||
|
|
|
@ -160,6 +160,15 @@ table {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error page
|
||||||
|
.large-error-icon {
|
||||||
|
float: left;
|
||||||
|
text-align: right;
|
||||||
|
font-size: 160px;
|
||||||
|
color: lightgrey;
|
||||||
|
margin-left: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
// Tasks ..
|
// Tasks ..
|
||||||
.accepted {
|
.accepted {
|
||||||
color: #468847;
|
color: #468847;
|
||||||
|
|
24
app/controllers/errors_controller.rb
Normal file
24
app/controllers/errors_controller.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
class ErrorsController < ApplicationController
|
||||||
|
include Gaffe::Errors
|
||||||
|
|
||||||
|
skip_before_filter :authenticate
|
||||||
|
|
||||||
|
layout :current_layout
|
||||||
|
|
||||||
|
def show
|
||||||
|
render "errors/#{@rescue_response}", status: @status_code
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def current_layout
|
||||||
|
# Need foodcoop for `current_user`, even though it may not be retrieved from the url.
|
||||||
|
params[:foodcoop] ||= session[:scope]
|
||||||
|
current_user ? 'application' : 'login'
|
||||||
|
end
|
||||||
|
|
||||||
|
def login_layout?
|
||||||
|
current_user.nil?
|
||||||
|
end
|
||||||
|
helper_method :login_layout?
|
||||||
|
end
|
9
app/views/errors/_error.html.haml
Normal file
9
app/views/errors/_error.html.haml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
- title local_assigns[:title], false
|
||||||
|
|
||||||
|
- unless login_layout?
|
||||||
|
%i.hidden-phone.large-error-icon.icon-exclamation-sign
|
||||||
|
%div(class="#{login_layout? ? '' : 'span6'}")
|
||||||
|
%h1= local_assigns[:title]
|
||||||
|
%div(class='alert alert-#{local_assigns[:type] || 'warn'}')
|
||||||
|
= local_assigns[:page]
|
||||||
|
= link_to t('ui.back'), 'javascript:history.go(-1)', class: 'btn btn-primary'
|
5
app/views/errors/internal_server_error.html.haml
Normal file
5
app/views/errors/internal_server_error.html.haml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
- page = capture do
|
||||||
|
%p= t '.text1'
|
||||||
|
%p= t '.text2'
|
||||||
|
|
||||||
|
= render 'error', title: t('.title'), type: :error, page: page
|
4
app/views/errors/not_found.html.haml
Normal file
4
app/views/errors/not_found.html.haml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
- page = capture do
|
||||||
|
%p= t '.text'
|
||||||
|
|
||||||
|
= render 'error', title: t('.title'), page: page
|
|
@ -1,3 +1,3 @@
|
||||||
- title t('.title')
|
- title t('.title')
|
||||||
= render :partial => 'form'
|
= render :partial => 'form'
|
||||||
= link_to t('.back'), finance_invoices_path
|
= link_to t('ui.or_cancel'), finance_invoices_path
|
||||||
|
|
|
@ -36,5 +36,4 @@
|
||||||
=h @invoice.note
|
=h @invoice.note
|
||||||
|
|
||||||
= link_to t('ui.edit'), edit_finance_invoice_path(@invoice)
|
= link_to t('ui.edit'), edit_finance_invoice_path(@invoice)
|
||||||
|
|
= link_to t('ui.or_cancel'), finance_invoices_path
|
||||||
= link_to t('.back'), finance_invoices_path
|
|
||||||
|
|
6
config/initializers/gaffe.rb
Normal file
6
config/initializers/gaffe.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
if Rails.env.production? || Rails.env.staging? || true
|
||||||
|
Gaffe.configure do |config|
|
||||||
|
config.errors_controller = 'ErrorsController'
|
||||||
|
end
|
||||||
|
Gaffe.enable!
|
||||||
|
end
|
|
@ -638,6 +638,13 @@ en:
|
||||||
general: A problem has occured.
|
general: A problem has occured.
|
||||||
general_again: A problem has occured. Please try again.
|
general_again: A problem has occured. Please try again.
|
||||||
general_msg: 'A problem has occured: %{msg}'
|
general_msg: 'A problem has occured: %{msg}'
|
||||||
|
not_found:
|
||||||
|
title: Page not found
|
||||||
|
text: This page does not appear to exist, sorry!
|
||||||
|
internal_server_error:
|
||||||
|
title: Internal server error
|
||||||
|
text1: An unexpected error has occured. Sorry!
|
||||||
|
text2: We've been notified. If this remains a problem, please tell us so.
|
||||||
feedback:
|
feedback:
|
||||||
create:
|
create:
|
||||||
notice: Your feedback was sent successfully. Thanks a lot!
|
notice: Your feedback was sent successfully. Thanks a lot!
|
||||||
|
@ -771,10 +778,8 @@ en:
|
||||||
linked_delivery: a delivery
|
linked_delivery: a delivery
|
||||||
linked_order: an order
|
linked_order: an order
|
||||||
new:
|
new:
|
||||||
back: Back
|
|
||||||
title: Create new invoice
|
title: Create new invoice
|
||||||
show:
|
show:
|
||||||
back: Back
|
|
||||||
title: Invoice %{number}
|
title: Invoice %{number}
|
||||||
ordergroups:
|
ordergroups:
|
||||||
index:
|
index:
|
||||||
|
@ -1685,6 +1690,7 @@ en:
|
||||||
title_all: All group tasks
|
title_all: All group tasks
|
||||||
ui:
|
ui:
|
||||||
actions: Actions
|
actions: Actions
|
||||||
|
back: Back
|
||||||
cancel: Cancel
|
cancel: Cancel
|
||||||
close: Close
|
close: Close
|
||||||
copy: Copy
|
copy: Copy
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
|
||||||
"http://www.w3.org/TR/html4/loose.dtd">
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Seite/Datei nicht gefunden!</h1>
|
|
||||||
<p>Das ist wohl eine Sackgasse und sollte eigentlich nicht vorkommen.</p>
|
|
||||||
<p>Bitte melden unter foodsoft [ätt] foodcoops.net</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in a new issue