diff options
| author | mo khan <mo@mokhan.ca> | 2017-02-26 13:21:30 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2017-02-26 13:21:30 -0700 |
| commit | d6c9788771f7dcbd96408130bc4e10e6497bee60 (patch) | |
| tree | 1a511d58856b2792b0ccb782a06df7a4e2663c21 | |
| parent | 5780e2d66fa27dd40bf5d3b581c68285c3199213 (diff) | |
add custom error pages.
| -rw-r--r-- | Gemfile | 1 | ||||
| -rw-r--r-- | Gemfile.lock | 3 | ||||
| -rw-r--r-- | app/controllers/api/errors_controller.rb | 12 | ||||
| -rw-r--r-- | app/controllers/errors_controller.rb | 8 | ||||
| -rw-r--r-- | app/views/errors/bad_request.html.erb | 7 | ||||
| -rw-r--r-- | app/views/errors/forbidden.html.erb | 7 | ||||
| -rw-r--r-- | app/views/errors/internal_server_error.html.erb | 7 | ||||
| -rw-r--r-- | app/views/errors/method_not_allowed.html.erb | 7 | ||||
| -rw-r--r-- | app/views/errors/not_acceptable.html.erb | 7 | ||||
| -rw-r--r-- | app/views/errors/not_found.html.erb | 7 | ||||
| -rw-r--r-- | app/views/errors/not_implemented.html.erb | 7 | ||||
| -rw-r--r-- | app/views/errors/unauthorized.html.erb | 7 | ||||
| -rw-r--r-- | app/views/errors/unprocessable_entity.html.erb | 7 | ||||
| -rw-r--r-- | config/initializers/gaffe.rb | 7 |
14 files changed, 94 insertions, 0 deletions
@@ -25,6 +25,7 @@ source "https://rubygems.org" do gem "flipper-redis" gem "font-awesome-rails" gem "foreman", group: :development + gem "gaffe" gem "geocoder" gem "geokit-rails" gem "griddler" diff --git a/Gemfile.lock b/Gemfile.lock index 2f0a7c1..ec774de 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -164,6 +164,8 @@ GEM railties (>= 3.2, < 5.1) foreman (0.82.0) thor (~> 0.19.1) + gaffe (1.2.0) + rails (>= 4.0.0) geocoder (1.3.7) geokit (1.10.0) geokit-rails (2.1.0) @@ -455,6 +457,7 @@ DEPENDENCIES flipper-redis! font-awesome-rails! foreman! + gaffe! geocoder! geokit-rails! griddler! diff --git a/app/controllers/api/errors_controller.rb b/app/controllers/api/errors_controller.rb new file mode 100644 index 0000000..09a7f16 --- /dev/null +++ b/app/controllers/api/errors_controller.rb @@ -0,0 +1,12 @@ +class API::ErrorsController < Api::Controller + include Gaffe::Errors + skip_before_action :authenticate! + + layout false + + def show + output = { error: @rescue_response } + output.merge! exception: @exception.inspect, backtrace: @exception.backtrace.first(10) if Rails.env.development? || Rails.env.test? + render json: output, status: @status_code + end +end diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 0000000..d6eabf5 --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -0,0 +1,8 @@ +class ErrorsController < PublicController + include Gaffe::Errors + layout "public" + + def show + render @rescue_response, status: @status_code + end +end diff --git a/app/views/errors/bad_request.html.erb b/app/views/errors/bad_request.html.erb new file mode 100644 index 0000000..f4b9423 --- /dev/null +++ b/app/views/errors/bad_request.html.erb @@ -0,0 +1,7 @@ +<div class="container"> + <div class="columns"> + <div class="column is-8 is-offset-2 has-text-centered"> + <h1 class="title">Bad Request</h1> + </div> + </div> +</div> diff --git a/app/views/errors/forbidden.html.erb b/app/views/errors/forbidden.html.erb new file mode 100644 index 0000000..d026b2e --- /dev/null +++ b/app/views/errors/forbidden.html.erb @@ -0,0 +1,7 @@ +<div class="container"> + <div class="columns"> + <div class="column is-8 is-offset-2 has-text-centered"> + <h1 class="title">Forbidden</h1> + </div> + </div> +</div> diff --git a/app/views/errors/internal_server_error.html.erb b/app/views/errors/internal_server_error.html.erb new file mode 100644 index 0000000..26d9119 --- /dev/null +++ b/app/views/errors/internal_server_error.html.erb @@ -0,0 +1,7 @@ +<div class="container"> + <div class="columns"> + <div class="column is-8 is-offset-2 has-text-centered"> + <h1 class="title">Internal Server Error</h1> + </div> + </div> +</div> diff --git a/app/views/errors/method_not_allowed.html.erb b/app/views/errors/method_not_allowed.html.erb new file mode 100644 index 0000000..1d94399 --- /dev/null +++ b/app/views/errors/method_not_allowed.html.erb @@ -0,0 +1,7 @@ +<div class="container"> + <div class="columns"> + <div class="column is-8 is-offset-2 has-text-centered"> + <h1 class="title">Method Not Allowed</h1> + </div> + </div> +</div> diff --git a/app/views/errors/not_acceptable.html.erb b/app/views/errors/not_acceptable.html.erb new file mode 100644 index 0000000..0f48aae --- /dev/null +++ b/app/views/errors/not_acceptable.html.erb @@ -0,0 +1,7 @@ +<div class="container"> + <div class="columns"> + <div class="column is-8 is-offset-2 has-text-centered"> + <h1 class="title">Not Acceptable</h1> + </div> + </div> +</div> diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb new file mode 100644 index 0000000..ad56df9 --- /dev/null +++ b/app/views/errors/not_found.html.erb @@ -0,0 +1,7 @@ +<div class="container"> + <div class="columns"> + <div class="column is-8 is-offset-2 has-text-centered"> + <h1 class="title">Not Found</h1> + </div> + </div> +</div> diff --git a/app/views/errors/not_implemented.html.erb b/app/views/errors/not_implemented.html.erb new file mode 100644 index 0000000..9bcc68e --- /dev/null +++ b/app/views/errors/not_implemented.html.erb @@ -0,0 +1,7 @@ +<div class="container"> + <div class="columns"> + <div class="column is-8 is-offset-2 has-text-centered"> + <h1 class="title">Not Implemented</h1> + </div> + </div> +</div> diff --git a/app/views/errors/unauthorized.html.erb b/app/views/errors/unauthorized.html.erb new file mode 100644 index 0000000..0c2d218 --- /dev/null +++ b/app/views/errors/unauthorized.html.erb @@ -0,0 +1,7 @@ +<div class="container"> + <div class="columns"> + <div class="column is-8 is-offset-2 has-text-centered"> + <h1 class="title">Unauthorized</h1> + </div> + </div> +</div> diff --git a/app/views/errors/unprocessable_entity.html.erb b/app/views/errors/unprocessable_entity.html.erb new file mode 100644 index 0000000..5b11640 --- /dev/null +++ b/app/views/errors/unprocessable_entity.html.erb @@ -0,0 +1,7 @@ +<div class="container"> + <div class="columns"> + <div class="column is-8 is-offset-2 has-text-centered"> + <h1 class="title">Unprocessable Entity</h1> + </div> + </div> +</div> diff --git a/config/initializers/gaffe.rb b/config/initializers/gaffe.rb new file mode 100644 index 0000000..c2fb532 --- /dev/null +++ b/config/initializers/gaffe.rb @@ -0,0 +1,7 @@ +Gaffe.configure do |config| + config.errors_controller = { + %r[^/api/] => 'Api::ErrorsController', + %r[^/] => 'ErrorsController', + } +end +Gaffe.enable! |
