exception_handler 0.7.5 → 0.8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +5 -5
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +51 -33
  4. data/.rspec +3 -4
  5. data/.slugignore +7 -0
  6. data/.travis.yml +13 -5
  7. data/Gemfile +16 -13
  8. data/README.md +643 -443
  9. data/Rakefile +7 -7
  10. data/app/assets/stylesheets/exception_handler.css.erb +23 -18
  11. data/app/assets/stylesheets/styles/_base.css.erb +28 -35
  12. data/app/assets/stylesheets/styles/_exception.css.erb +106 -105
  13. data/app/assets/stylesheets/styles/_footer.css.erb +24 -24
  14. data/app/assets/stylesheets/styles/_responsive.css +5 -5
  15. data/app/controllers/exception_handler/exceptions_controller.rb +66 -55
  16. data/app/mailers/exception_handler/exception_mailer.rb +17 -17
  17. data/app/models/exception_handler/exception.rb +200 -191
  18. data/app/views/exception_handler/exceptions/show.html.erb +3 -3
  19. data/app/views/exception_handler/mailers/layout.haml +8 -8
  20. data/app/views/exception_handler/mailers/layout.text.erb +1 -1
  21. data/app/views/exception_handler/mailers/new_exception.erb +4 -4
  22. data/app/views/layouts/exception.html.erb +32 -27
  23. data/app/views/layouts/mailer.html.erb +5 -0
  24. data/app/views/layouts/mailer.text.erb +1 -0
  25. data/config/locales/exception_handler.en.yml +28 -29
  26. data/config/routes.rb +42 -0
  27. data/db/migrate/000000_create_errors.rb +34 -34
  28. data/exception_handler.gemspec +64 -80
  29. data/lib/exception_handler.rb +56 -45
  30. data/lib/exception_handler/config.rb +185 -103
  31. data/lib/exception_handler/engine.rb +78 -60
  32. data/lib/exception_handler/version.rb +25 -0
  33. data/lib/generators/exception_handler/views_generator.rb +33 -33
  34. data/spec/controllers/controller_spec.rb +107 -0
  35. data/spec/dummy/.rspec +1 -0
  36. data/spec/dummy/.ruby-version +1 -0
  37. data/spec/dummy/Rakefile +6 -6
  38. data/spec/dummy/app/assets/config/manifest.js +3 -4
  39. data/spec/dummy/app/assets/javascripts/application.js +15 -13
  40. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  41. data/spec/dummy/app/assets/stylesheets/application.css +15 -15
  42. data/spec/dummy/app/channels/application_cable/channel.rb +4 -5
  43. data/spec/dummy/app/channels/application_cable/connection.rb +4 -5
  44. data/spec/dummy/app/controllers/application_controller.rb +2 -5
  45. data/spec/dummy/app/helpers/application_helper.rb +2 -2
  46. data/spec/dummy/app/jobs/application_job.rb +2 -2
  47. data/spec/dummy/app/mailers/application_mailer.rb +4 -4
  48. data/spec/dummy/app/models/application_record.rb +3 -3
  49. data/spec/dummy/app/views/layouts/application.html.erb +15 -15
  50. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -13
  51. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -1
  52. data/spec/dummy/bin/bundle +3 -3
  53. data/spec/dummy/bin/rails +4 -4
  54. data/spec/dummy/bin/rake +4 -4
  55. data/spec/dummy/bin/setup +36 -34
  56. data/spec/dummy/bin/update +31 -29
  57. data/spec/dummy/bin/yarn +11 -0
  58. data/spec/dummy/config.ru +5 -8
  59. data/spec/dummy/config/application.rb +18 -21
  60. data/spec/dummy/config/boot.rb +5 -5
  61. data/spec/dummy/config/cable.yml +10 -10
  62. data/spec/dummy/config/database.yml +25 -25
  63. data/spec/dummy/config/environment.rb +5 -5
  64. data/spec/dummy/config/environments/development.rb +61 -62
  65. data/spec/dummy/config/environments/production.rb +94 -87
  66. data/spec/dummy/config/environments/test.rb +46 -42
  67. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -6
  68. data/spec/dummy/config/initializers/assets.rb +14 -11
  69. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
  70. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  71. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -5
  72. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
  73. data/spec/dummy/config/initializers/inflections.rb +16 -16
  74. data/spec/dummy/config/initializers/mime_types.rb +4 -4
  75. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  76. data/spec/dummy/config/locales/en.yml +33 -23
  77. data/spec/dummy/config/puma.rb +34 -47
  78. data/spec/dummy/config/routes.rb +3 -6
  79. data/spec/dummy/config/storage.yml +34 -0
  80. data/spec/dummy/package.json +5 -0
  81. data/spec/dummy/public/404.html +67 -67
  82. data/spec/dummy/public/422.html +67 -67
  83. data/spec/dummy/public/500.html +66 -66
  84. data/spec/dummy/spec/rails_helper.rb +57 -0
  85. data/spec/dummy/spec/spec_helper.rb +100 -0
  86. data/spec/dummy/storage/.keep +0 -0
  87. data/spec/features/asset_spec.rb +61 -0
  88. data/spec/features/config_spec.rb +51 -0
  89. data/spec/features/engine_spec.rb +180 -0
  90. data/spec/mailers/mailer_spec.rb +26 -0
  91. data/spec/models/model_spec.rb +26 -0
  92. data/spec/routing/routing_spec.rb +85 -0
  93. data/spec/spec_helper.rb +101 -55
  94. data/spec/views/views_spec.rb +29 -0
  95. metadata +54 -28
  96. data/.gitattributes +0 -1
  97. data/LICENSE.txt +0 -22
  98. data/app/assets/images/exception_handler/bg.jpg +0 -0
  99. data/app/assets/images/exception_handler/bg_overlay.png +0 -0
  100. data/spec/database.yml +0 -3
  101. data/spec/dummy/app/assets/javascripts/cable.coffee +0 -11
  102. data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +0 -6
  103. data/spec/dummy/config/initializers/callback_terminator.rb +0 -6
  104. data/spec/dummy/config/initializers/per_form_csrf_tokens.rb +0 -4
  105. data/spec/dummy/config/initializers/request_forgery_protection.rb +0 -4
  106. data/spec/dummy/config/initializers/session_store.rb +0 -3
  107. data/spec/dummy/config/secrets.yml +0 -22
  108. data/spec/exception_handler.rb +0 -22
  109. data/spec/exception_handler/exception_controller_spec.rb +0 -18
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- ###########################################
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ ###########################################
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
8
  task default: :spec
@@ -1,18 +1,23 @@
1
- /* ---------------------------------------------------- */
2
- /* ---------------------------------------------------- */
3
- /* _____ _____ _____ */
4
- /* / __ \/ ___/ ___| */
5
- /* | / \/\ `--.\ `--. */
6
- /* | | `--. \`--. \ */
7
- /* | \__/\/\__/ /\__/ / */
8
- /* \____/\____/\_____/ */
9
- /* */
10
- /* ---------------------------------------------------- */
11
- /* ---------------------------------------------------- */
12
- /*
13
- *= require_self
14
- *= require_tree ./styles
15
- */
16
- /* ---------------------------------------------------- */
17
- /* ---------------------------------------------------- */
18
- /* ---------------------------------------------------- */
1
+ /* ---------------------------------------------------- */
2
+ /* ---------------------------------------------------- */
3
+ /* _____ _____ _____ */
4
+ /* / __ \/ ___/ ___| */
5
+ /* | / \/\ `--.\ `--. */
6
+ /* | | `--. \`--. \ */
7
+ /* | \__/\/\__/ /\__/ / */
8
+ /* \____/\____/\_____/ */
9
+ /* */
10
+ /* ---------------------------------------------------- */
11
+ /* ---------------------------------------------------- */
12
+ /*
13
+ *= require_self
14
+ *= require_tree ./styles
15
+ */
16
+ /* ---------------------------------------------------- */
17
+ /* ---------------------------------------------------- */
18
+ /*
19
+ *= link_tree ../images
20
+ */
21
+ /* ---------------------------------------------------- */
22
+ /* ---------------------------------------------------- */
23
+ /* ---------------------------------------------------- */
@@ -1,35 +1,28 @@
1
- /* ---------------------------------------------------- */
2
- /* ---------------------------------------------------- */
3
- /* Dependencies */
4
- /* ---------------------------------------------------- */
5
- /* ---------------------------------------------------- */
6
-
7
- /*
8
- *= link_tree ../../images
9
- */
10
-
11
- /* ---------------------------------------------------- */
12
- /* ---------------------------------------------------- */
13
-
14
- * { margin: 0; }
15
- html, body { height: 100%; }
16
- html {
17
- height: 100%;
18
- color: #fff;
19
- background: #010008 url(<%= asset_url("exception_handler/bg.jpg") %>) top left no-repeat;
20
- background-size: 100% 100%;
21
- box-sizing: border-box;
22
- }
23
- body {
24
- position: relative;
25
- font-family: Helvetica, Arial, Sans-Serif;
26
- font-size: 12px;
27
- text-transform: capitalize;
28
- box-sizing: border-box;
29
- overflow-x: hidden;
30
- }
31
- a { color: #fff; text-decoration: none; }
32
- a:hover { text-decoration: underline; }
33
-
34
- /* ---------------------------------------------------- */
35
- /* ---------------------------------------------------- */
1
+ /* ---------------------------------------------------- */
2
+ /* ---------------------------------------------------- */
3
+ /* Dependencies */
4
+ /* ---------------------------------------------------- */
5
+ /* ---------------------------------------------------- */
6
+
7
+ * { margin: 0; }
8
+ html, body { height: 100%; }
9
+ html {
10
+ height: 100%;
11
+ color: #fff;
12
+ background: #121212;
13
+ background-size: 100% 100%;
14
+ box-sizing: border-box;
15
+ }
16
+ body {
17
+ position: relative;
18
+ font-family: Helvetica, Arial, Sans-Serif;
19
+ font-size: 12px;
20
+ text-transform: capitalize;
21
+ box-sizing: border-box;
22
+ overflow-x: hidden;
23
+ }
24
+ a { color: #fff; text-decoration: none; }
25
+ a:hover { text-decoration: underline; }
26
+
27
+ /* ---------------------------------------------------- */
28
+ /* ---------------------------------------------------- */
@@ -1,105 +1,106 @@
1
- /* ---------------------------------------------------- */
2
- /* ---------------------------------------------------- */
3
-
4
- .exception {
5
- display: block;
6
- color: rgba(0,0,0,1);
7
- position: relative;
8
- width: 20%;
9
- top: 48%;
10
- margin: auto;
11
- border: 1px solid rgba(0,0,0,1);
12
- max-width: 400px;
13
- min-width: 350px;
14
- border-radius: 5px;
15
- box-sizing: border-box;
16
- box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.5);
17
- background: rgba(16,0,1,1);
18
- background-image: linear-gradient(to bottom, rgba(16,0,1,1) 70%,rgba(0,0,0,1) 100%);
19
- background-clip: content-box;
20
- overflow-x: hidden;
21
- overflow-y: hidden;
22
- transition: background 0.1s ease-in-out;
23
- transform: translateY(-50%);
24
- z-index: 10;
25
- }
26
- .exception::before {
27
- content: url(<%= asset_url("exception_handler/icon.png") %>) " " attr(data-response);
28
- display: block;
29
- color: rgba(255,255,255,1);
30
- font-size: 1.25em;
31
- font-weight: bold;
32
- text-transform: capitalize;
33
- padding: 1em;
34
- line-height: 10px;
35
- text-shadow: 0 1px 0 rgba(0,0,0,1);
36
- border-bottom: 1px solid rgba(122,11,11,1);
37
- vertical-align: middle;
38
- background-color: rgba(227,11,11,1);
39
- background-image: url(<%= asset_url("exception_handler/noise.png") %>), linear-gradient(to bottom, rgba(227,11,11,0) 0%,rgba(0,0,0,0.55) 100%); /* W3C */
40
- filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#007a07ed', endColorstr='#000000',GradientType=0 ); /* IE6-9 */
41
- }
42
- .exception::after {
43
- content: attr(data-rails) " \203A\203A Our developers have been notified. Click here to go home.";
44
- display: block;
45
- padding: 1em;
46
- font-size: 0.8em;
47
- line-height: 11px;
48
- color: rgba(255,255,255,1);
49
- text-align: center;
50
- box-sizing: border-box;
51
-
52
- border-width: 0 1px 1px;
53
- border-color: rgba(255,255,255,0.09);
54
- border-style: solid
55
- }
56
- .exception:hover { cursor: pointer; }
57
-
58
- .exception span:before {
59
- display: block;
60
- content: url(<%= asset_url("exception_handler/alert.png") %>);
61
- padding: 3.5em 0 1em;
62
- text-align: center;
63
- }
64
- .exception span {
65
- position: relative;
66
- display: block;
67
- min-height: 288px;
68
- color: rgba(255,255,255,1);
69
- padding: 0 2.5em 3em;
70
- box-sizing: border-box;
71
- background-clip: border-box;
72
- text-align: center;
73
- background: url(<%= asset_url("exception_handler/alert.jpg") %>) top center no-repeat;
74
-
75
- border-top: 1px solid rgba(0,0,0,0.05);
76
- border-left: 1px solid rgba(255,255,255,0.08);
77
- border-right: 1px solid rgba(255,255,255,0.08);
78
- }
79
- .exception span:after {
80
- content: "";
81
- display: block;
82
- position: absolute;
83
- left: 0;
84
- top: 0;
85
- width: 100%;
86
- height: 2px;
87
-
88
- background: rgba(0,0,0,0.35);
89
- background: -moz-linear-gradient(top, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 100%);
90
- background: -webkit-gradient(left top, left bottom, color-stop(0%, rgba(0,0,0,0.35)), color-stop(100%, rgba(0,0,0,0)));
91
- background: -webkit-linear-gradient(top, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 100%);
92
- background: -o-linear-gradient(top, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 100%);
93
- background: -ms-linear-gradient(top, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 100%);
94
- background: linear-gradient(to bottom, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 100%);
95
- filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#000000', GradientType=0 );
96
- }
97
- .exception span strong {
98
- display: block;
99
- font-size: 2em;
100
- margin: 1em 0 0.25em;
101
- text-transform: uppercase;
102
- }
103
- .exception span p { display: block; margin-top: 1.5em; font-size: 0.85em; text-decoration: underline; }
104
- /* ---------------------------------------------------- */
105
- /* ---------------------------------------------------- */
1
+ /* ---------------------------------------------------- */
2
+ /* ---------------------------------------------------- */
3
+
4
+ .exception {
5
+ display: block;
6
+ color: rgba(0,0,0,1);
7
+ position: relative;
8
+ width: 20%;
9
+ top: 48%;
10
+ margin: auto;
11
+ border: 1px solid rgba(0,0,0,1);
12
+ max-width: 400px;
13
+ min-width: 350px;
14
+ border-radius: 5px;
15
+ box-sizing: border-box;
16
+ box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.5);
17
+ background: rgba(16,0,1,1);
18
+ background-image: linear-gradient(to bottom, rgba(16,0,1,1) 70%,rgba(0,0,0,1) 100%);
19
+ background-clip: content-box;
20
+ overflow-x: hidden;
21
+ overflow-y: hidden;
22
+ transition: background 0.1s ease-in-out;
23
+ transform: translateY(-50%);
24
+ z-index: 10;
25
+ }
26
+ .exception::before {
27
+ content: url(<%= asset_url("exception_handler/icon.png") %>) " " attr(data-response);
28
+ display: block;
29
+ color: rgba(255,255,255,1);
30
+ font-size: 1.25em;
31
+ font-weight: bold;
32
+ text-transform: capitalize;
33
+ padding: 1em;
34
+ line-height: 10px;
35
+ text-shadow: 0 1px 0 rgba(0,0,0,1);
36
+ border-bottom: 1px solid rgba(122,11,11,1);
37
+ vertical-align: middle;
38
+ background-color: rgba(227,11,11,1);
39
+ background-image: url(<%= asset_url("exception_handler/noise.png") %>), linear-gradient(to bottom, rgba(227,11,11,0) 0%,rgba(0,0,0,0.55) 100%); /* W3C */
40
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#007a07ed', endColorstr='#000000',GradientType=0 ); /* IE6-9 */
41
+ }
42
+ .exception::after {
43
+ content: attr(data-rails) " \203A\203A Our developers have been notified. Click here to go home.";
44
+ display: block;
45
+ padding: 1em;
46
+ font-size: 0.8em;
47
+ line-height: 11px;
48
+ color: rgba(255,255,255,1);
49
+ text-align: center;
50
+ box-sizing: border-box;
51
+
52
+ border-width: 0 1px 1px;
53
+ border-color: rgba(255,255,255,0.09);
54
+ border-style: solid
55
+ }
56
+ .exception:hover { cursor: pointer; }
57
+ .exception:hover:after { text-decoration: underline; }
58
+
59
+ .exception span:before {
60
+ display: block;
61
+ content: url(<%= asset_url("exception_handler/alert.png") %>);
62
+ padding: 3.5em 0 1em;
63
+ text-align: center;
64
+ }
65
+ .exception span {
66
+ position: relative;
67
+ display: block;
68
+ min-height: 288px;
69
+ color: rgba(255,255,255,1);
70
+ padding: 0 2.5em 3em;
71
+ box-sizing: border-box;
72
+ background-clip: border-box;
73
+ text-align: center;
74
+ background: url(<%= asset_url("exception_handler/alert.jpg") %>) top center no-repeat;
75
+
76
+ border-top: 1px solid rgba(0,0,0,0.05);
77
+ border-left: 1px solid rgba(255,255,255,0.08);
78
+ border-right: 1px solid rgba(255,255,255,0.08);
79
+ }
80
+ .exception span:after {
81
+ content: "";
82
+ display: block;
83
+ position: absolute;
84
+ left: 0;
85
+ top: 0;
86
+ width: 100%;
87
+ height: 2px;
88
+
89
+ background: rgba(0,0,0,0.35);
90
+ background: -moz-linear-gradient(top, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 100%);
91
+ background: -webkit-gradient(left top, left bottom, color-stop(0%, rgba(0,0,0,0.35)), color-stop(100%, rgba(0,0,0,0)));
92
+ background: -webkit-linear-gradient(top, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 100%);
93
+ background: -o-linear-gradient(top, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 100%);
94
+ background: -ms-linear-gradient(top, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 100%);
95
+ background: linear-gradient(to bottom, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 100%);
96
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#000000', GradientType=0 );
97
+ }
98
+ .exception span strong {
99
+ display: block;
100
+ font-size: 2em;
101
+ margin: 1em 0 0.25em;
102
+ text-transform: uppercase;
103
+ }
104
+ .exception span p { display: block; margin-top: 1.5em; font-size: 0.85em; text-decoration: underline; }
105
+ /* ---------------------------------------------------- */
106
+ /* ---------------------------------------------------- */
@@ -1,24 +1,24 @@
1
- /* ---------------------------------------------------- */
2
- /* ---------------------------------------------------- */
3
-
4
- footer {
5
- display: block;
6
- position: absolute;
7
- bottom: 0;
8
- width: 100%;
9
- font-size: 2em;
10
- text-align: center;
11
- vertical-align: middle;
12
- }
13
- footer a {
14
- display: inline-block;
15
- margin-right: -4px;
16
- padding: 1.5em 0.3em;
17
- vertical-align: middle;
18
- transition: opacity 0.15s ease-in-out;
19
- }
20
- footer a:hover { text-decoration: none; }
21
- footer a img { width: 30px; vertical-align: middle; }
22
-
23
- /* ---------------------------------------------------- */
24
- /* ---------------------------------------------------- */
1
+ /* ---------------------------------------------------- */
2
+ /* ---------------------------------------------------- */
3
+
4
+ footer {
5
+ display: block;
6
+ position: absolute;
7
+ bottom: 0;
8
+ width: 100%;
9
+ font-size: 2em;
10
+ text-align: center;
11
+ vertical-align: middle;
12
+ }
13
+ footer a {
14
+ display: inline-block;
15
+ margin-right: -4px;
16
+ padding: 1.5em 0.3em;
17
+ vertical-align: middle;
18
+ transition: opacity 0.15s ease-in-out;
19
+ }
20
+ footer a:hover { text-decoration: none; }
21
+ footer a img { width: 30px; vertical-align: middle; }
22
+
23
+ /* ---------------------------------------------------- */
24
+ /* ---------------------------------------------------- */
@@ -1,5 +1,5 @@
1
- /* Responsive */
2
- @media screen and (max-width: 950px) {
3
- html { background-size: cover !important; }
4
- .container .error { width: 55% !important; }
5
- }
1
+ /* Responsive */
2
+ @media screen and (max-width: 950px) {
3
+ html { background-size: cover !important; }
4
+ .container .error { width: 55% !important; }
5
+ }
@@ -1,55 +1,66 @@
1
- module ExceptionHandler
2
- class ExceptionsController < ApplicationController
3
-
4
- # => Response
5
- # => http://www.justinweiss.com/articles/respond-to-without-all-the-pain/
6
- respond_to :html, :js, :json, :xml
7
-
8
- # => CSRF
9
- protect_from_forgery
10
-
11
- ##################################
12
- ##################################
13
-
14
- # => Definitions
15
- # => Exception model (tied to DB)
16
- before_action { |e| @exception = ExceptionHandler::Exception.new request: e.request }
17
- before_action { @exception.save if @exception.valid? && ExceptionHandler.config.try(:db) }
18
-
19
- # => Response format (required for non-standard formats (.css / .gz etc))
20
- # => request.format required until responders updates with wildcard / failsafe (:all)
21
- before_action { |e| e.request.format = :html unless self.class.respond_to.include? e.request.format }
22
-
23
- # => Routes
24
- # => Removes need for "main_app" prefix in routes
25
- # => http://stackoverflow.com/a/40251516/1143732
26
- helper Rails.application.routes.url_helpers
27
-
28
- # => Layout
29
- # => Layouts only 400 / 500 because they are the only error responses (300 is redirect)
30
- # => http://guides.rubyonrails.org/layouts_and_rendering.html#the-status-option
31
- # => Layout proc kills "nil" inheritance, needs to be method for now
32
- layout :layout
33
-
34
- ####################
35
- # Action #
36
- ####################
37
-
38
- def show
39
- respond_with @exception, status: @exception.status
40
- end
41
-
42
- ##################################
43
- ##################################
44
-
45
- private
46
-
47
- def layout
48
- ExceptionHandler.config.layouts[@exception.status]
49
- end
50
-
51
- ##################################
52
- ##################################
53
-
54
- end
55
- end
1
+ module ExceptionHandler
2
+ class ExceptionsController < ApplicationController
3
+
4
+ # => Response
5
+ # => http://www.justinweiss.com/articles/respond-to-without-all-the-pain/
6
+ respond_to :html, :js, :json, :xml
7
+
8
+ # => CSRF
9
+ protect_from_forgery
10
+
11
+ # => Devise
12
+ # => http://stackoverflow.com/a/38531245/1143732
13
+ skip_before_action :authenticate_user!, raise: false
14
+
15
+ ##################################
16
+ ##################################
17
+
18
+ # => Definitions
19
+ # => Exception model (tied to DB)
20
+ before_action { |e| @exception = ExceptionHandler::Exception.new request: e.request }
21
+ before_action { @exception.save if @exception.valid? && ExceptionHandler.config.try(:db) }
22
+
23
+ # => Response format (required for non-standard formats (.css / .gz etc))
24
+ # => request.format required until responders updates with wildcard / failsafe (:all)
25
+ before_action { |e| e.request.format = :html unless self.class.respond_to.include? e.request.format }
26
+
27
+ # => Routes
28
+ # => Removes need for "main_app" prefix in routes
29
+ # => http://stackoverflow.com/a/40251516/1143732
30
+ helper Rails.application.routes.url_helpers
31
+
32
+ # => Layout
33
+ # => Layouts only 400 / 500 because they are the only error responses (300 is redirect)
34
+ # => http://guides.rubyonrails.org/layouts_and_rendering.html#the-status-option
35
+ # => Layout proc kills "nil" inheritance, needs to be method for now
36
+ layout :layout
37
+
38
+ ####################
39
+ # Actions #
40
+ ####################
41
+
42
+ # => General Show Functionality
43
+ # => Introduced new "action" config option in 0.8.0.0
44
+ def show
45
+ respond_with @exception, status: @exception.status
46
+ end
47
+
48
+ ##################################
49
+ ##################################
50
+
51
+ private
52
+
53
+ # => Pulls from Exception class
54
+ # => Spanner in the works is nil
55
+ # => .present? validates against empty strings (IE a string is present)
56
+ # => .nil? validates to see if the returned data is "nil"
57
+ # => nil required to facilitate inheritance of the layout w/ ApplicationController
58
+ def layout option = ExceptionHandler.config.options(@exception.status, :layout)
59
+ (option.present? || option.nil?) ? option : 'exception'
60
+ end
61
+
62
+ ##################################
63
+ ##################################
64
+
65
+ end
66
+ end