Skip to content

Commit

Permalink
Handle errors using Gaffe
Browse files Browse the repository at this point in the history
  • Loading branch information
wvengen committed Jul 20, 2015
1 parent ae4979a commit 9efa9d5
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 17 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ gem 'recurring_select'
gem 'roo', '~> 2.0.0'
gem 'roo-xls'
gem 'spreadsheet'
gem 'gaffe'

# 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'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ GEM
faker (1.4.3)
i18n (~> 0.5)
ffi (1.9.10)
gaffe (1.0.2)
rails (>= 3.2.0)
git-version-bump (0.15.1)
globalid (0.3.5)
activesupport (>= 4.1.0)
Expand Down Expand Up @@ -488,6 +490,7 @@ DEPENDENCIES
faker
foodsoft_messages!
foodsoft_wiki!
gaffe
haml-rails
i18n-js (~> 3.0.0.rc8)
i18n-spec
Expand Down
9 changes: 9 additions & 0 deletions app/assets/stylesheets/bootstrap_and_overrides.css.less
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ table {
}
}

// Error page
.large-error-icon {
float: left;
text-align: right;
font-size: 160px;
color: lightgrey;
margin-left: 25px;
}

// Tasks ..
.accepted {
color: #468847;
Expand Down
24 changes: 24 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions app/views/errors/_error.html.haml
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions app/views/errors/internal_server_error.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- page = capture do
%p= t '.text1'
%p= t '.text2'

= render 'error', title: t('.title'), type: :error, page: page
4 changes: 4 additions & 0 deletions app/views/errors/not_found.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- page = capture do
%p= t '.text'

= render 'error', title: t('.title'), page: page
2 changes: 1 addition & 1 deletion app/views/finance/invoices/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- title t('.title')
= render :partial => 'form'
= link_to t('.back'), finance_invoices_path
= link_to t('ui.or_cancel'), finance_invoices_path
3 changes: 1 addition & 2 deletions app/views/finance/invoices/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@
=h @invoice.note

= link_to t('ui.edit'), edit_finance_invoice_path(@invoice)
|
= link_to t('.back'), finance_invoices_path
= link_to t('ui.or_cancel'), finance_invoices_path
6 changes: 6 additions & 0 deletions config/initializers/gaffe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if Rails.env.production? || Rails.env.staging? || true
Gaffe.configure do |config|
config.errors_controller = 'ErrorsController'
end
Gaffe.enable!
end
10 changes: 8 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,13 @@ en:
general: A problem has occured.
general_again: A problem has occured. Please try again.
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:
create:
notice: Your feedback was sent successfully. Thanks a lot!
Expand Down Expand Up @@ -771,10 +778,8 @@ en:
linked_delivery: a delivery
linked_order: an order
new:
back: Back
title: Create new invoice
show:
back: Back
title: Invoice %{number}
ordergroups:
index:
Expand Down Expand Up @@ -1685,6 +1690,7 @@ en:
title_all: All group tasks
ui:
actions: Actions
back: Back
cancel: Cancel
close: Close
copy: Copy
Expand Down
12 changes: 0 additions & 12 deletions public/404.html

This file was deleted.

0 comments on commit 9efa9d5

Please sign in to comment.