openstax_rescue_from 1.2.0 → 1.3.0

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDA1Mzg0OTJkMDhiMDFmOTk0NDExNGJiZmQ5ZDU4ZWE1NzYyY2E2Yw==
4
+ ZjY0Mjk0YjIwNjgwNjE4ZDQ5MTFhNDdmNzIwNGRkNzc5MDFlOWRlMw==
5
5
  data.tar.gz: !binary |-
6
- ZDIyNjBlZmFhNDY3MDNhMGVkYzllMDk1OWZkOGQwNTI0NWMwMTQ0Zg==
6
+ NzJlZDRmNjMwNjdmMzUwMzgyNTIwMGYzN2NmNWZhZTM1Njg5MjU4Nw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmJmODJmNjk5OTg0NTRlNTE1YTVjNzJmNWEwOTczNmNjNDMzYWJhNWUxMDkw
10
- ZmI4MjdhMWM4NDkwMzNmNGIxNDgxOWE2ODFiZTg1NDhmNzU1OTlkNDA5Nzcy
11
- NTA4ZjUxYTdhYWU2MGUzNzhlNGE3NjI0N2Y2MzFiNjMwYjJiZDI=
9
+ NDBmMTJiOTg1ZGQwODhjZTM4NWZjY2ZhMTNhMTc2MGYzODdkZGRmZWRlMGYy
10
+ MmNmMTA1M2VmMTcyNjE0NGIzNzZlN2UxNzhmM2QyMzhlODY3MWY2ZDg3OGU4
11
+ OGRiZWU1MDRhY2I0NGQ0Mjc5NDk5ZGE5MTZkMGNhMzk5YzNiMjg=
12
12
  data.tar.gz: !binary |-
13
- ZDllNDEzY2FlMTgwMjI1ZjliYTNhNWY1MzU4NzM3NmM2OTJiMjI1Mjg3MmFi
14
- MDcxY2QxNmVlZTFmM2YyYmMwMmVhNjVhNjZjZjhiMzFlYmRhOTU3NjA5MjZh
15
- ZTk0YTg5MTk0OGM2ZmNmZjJmZGU0MTk2YjQ0YmZiMTM2M2ZjMDk=
13
+ YzczZDMwZGVhN2I1ODg1NGY0NGY3ODg0ZmMxMzgxNDgwODliMzFlMTAyNzk1
14
+ YzZmYjQ5MGVhY2Q3MmJmYzhiNjhmNjIzYmZjNWIyYzA3NjZlNDAzOWU4OWIw
15
+ N2Y1MGZhZDNiMDY3MGUxYjhhNWIzYmI3MzkwZTJlM2Q5M2JhYzI=
data/README.md CHANGED
@@ -44,7 +44,7 @@ class ApplicationController < ActionController::Base
44
44
  # Override the rescued hook which is called when configuration.raise_exceptions is false
45
45
  # (See 'Controller hook')
46
46
  #
47
- # def openstax_exception_rescued(exception_proxy)
47
+ # def openstax_exception_rescued(exception_proxy, did_notify)
48
48
  # app_name = openstax_rescue_config.app_name
49
49
  # # RescueFrom.configuration private method available to you
50
50
  #
@@ -136,8 +136,14 @@ OpenStax::RescueFrom.translate_status_codes({
136
136
  #
137
137
  # -- check your OpenStax::RescueFrom.configuration.raise_exceptions setting --
138
138
  #
139
+ # Params:
140
+ # exception_proxy - an OpenStax::RescueFrom::ExceptionProxy wrapper around
141
+ # the exception
142
+ # did_notify - true iff the exception was sent out to notification channels
143
+ # such as email or the log file
144
+ #
139
145
 
140
- def openstax_exception_rescued(exception_proxy)
146
+ def openstax_exception_rescued(exception_proxy, did_notify)
141
147
  @message = exception_proxy.friendly_message
142
148
  @status = exception_proxy.status
143
149
  @error_id = exception_proxy.error_id
@@ -1,4 +1,4 @@
1
- <h3><%= @message %></h3>
1
+ <h3 class='rescue-from'><%= @message %></h3>
2
2
 
3
- <p>We're sorry this <%= @code %> error occurred. If you need help, please contact <%= openstax_rescue_from_contact_info %><%= " and reference error #{@error_id}" if @error_id %>.</p>
3
+ <p class='rescue-from'>We're sorry this <%= @code %> error occurred. If you need help, please contact <%= openstax_rescue_from_contact_info %><%= " and reference error #{@error_id}" if @error_id && @did_notify %>.</p>
4
4
 
@@ -49,7 +49,7 @@ end
49
49
  #
50
50
  # Default:
51
51
  # - internal_server_error: "Sorry, #{OpenStax::RescueFrom.configuration.app_name} had some unexpected trouble with your request."
52
- # - not_found: 'Sorry, we could not find that resource.',
52
+ # - not_found: 'We could not find the requested information.',
53
53
  # - bad_request: 'The request was unrecognized.',
54
54
  # - forbidden: 'You are not allowed to do that.'
55
- # - unprocessable_entity: 'The entity could not be processed.'
55
+ # - unprocessable_entity: 'Your browser asked for something that we cannot do.'
@@ -5,9 +5,15 @@ module OpenStax
5
5
  class Configuration
6
6
 
7
7
  attr_accessor :raise_exceptions, :notifier, :html_error_template_path,
8
- :html_error_template_layout_name, :app_name, :app_env, :contact_name,
8
+ :html_error_template_layout_name, :app_name, :app_env,
9
9
  :email_prefix, :sender_address, :exception_recipients
10
10
 
11
+ attr_writer :contact_name
12
+
13
+ def contact_name
14
+ @contact_name || "us"
15
+ end
16
+
11
17
  def initialize
12
18
  @raise_exceptions = ![false, 'false'].include?(ENV['RAISE_EXCEPTIONS'])
13
19
 
@@ -13,17 +13,19 @@ module OpenStax
13
13
  end
14
14
  end
15
15
 
16
- def openstax_exception_rescued(proxy)
16
+ def openstax_exception_rescued(proxy, did_notify)
17
17
  @message = proxy.friendly_message
18
18
  @code = proxy.status_code
19
19
  @error_id = proxy.error_id
20
+ @did_notify = did_notify
20
21
 
21
22
  respond_to do |f|
22
23
  f.html { render template: openstax_rescue_config.html_error_template_path,
23
24
  layout: openstax_rescue_config.html_error_template_layout_name,
24
25
  status: proxy.status }
25
26
 
26
- f.json { render json: { error_id: proxy.error_id }, status: proxy.status }
27
+ f.json { render json: { error_id: did_notify ? proxy.error_id : nil },
28
+ status: proxy.status }
27
29
 
28
30
  f.all { render nothing: true, status: proxy.status }
29
31
  end
@@ -1,7 +1,7 @@
1
1
  module OpenStax
2
2
  module RescueFrom
3
3
  class MuteListener
4
- def openstax_exception_rescued(proxy)
4
+ def openstax_exception_rescued(proxy, _)
5
5
  Rails.logger.warn("MuteListener does nothing after rescuing " +
6
6
  "ExceptionProxy#error_id #=> #{proxy.error_id}")
7
7
  end
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module RescueFrom
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -62,7 +62,7 @@ module OpenStax
62
62
  end
63
63
 
64
64
  def generate_id
65
- "%06d#{SecureRandom.random_number(10**6)}"
65
+ sprintf "%06d", "#{SecureRandom.random_number(10**6)}"
66
66
  end
67
67
 
68
68
  def configure
@@ -77,10 +77,10 @@ module OpenStax
77
77
  def friendly_status_messages
78
78
  @@friendly_status_messages ||= {
79
79
  internal_server_error: default_friendly_message,
80
- :not_found => 'Sorry, we could not find that resource.',
80
+ :not_found => 'We could not find the requested information.',
81
81
  bad_request: 'The request was unrecognized.',
82
82
  forbidden: 'You are not allowed to do that.',
83
- unprocessable_entity: 'The entity could not be processed.'
83
+ unprocessable_entity: 'Your browser asked for something that we cannot do.'
84
84
  }
85
85
  end
86
86
 
@@ -93,8 +93,10 @@ module OpenStax
93
93
  end
94
94
 
95
95
  def log_system_error(proxy)
96
- logger = Logger.new(proxy)
97
- logger.record_system_error!
96
+ if notifies_for?(proxy.name)
97
+ logger = Logger.new(proxy)
98
+ logger.record_system_error!
99
+ end
98
100
  end
99
101
 
100
102
  def send_notifying_exceptions(proxy, listener)
@@ -120,7 +122,7 @@ module OpenStax
120
122
  if configuration.raise_exceptions
121
123
  raise proxy.exception
122
124
  else
123
- listener.openstax_exception_rescued(proxy)
125
+ listener.openstax_exception_rescued(proxy, notifies_for?(proxy.name))
124
126
  end
125
127
  end
126
128
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_rescue_from
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-10-06 00:00:00.000000000 Z
12
+ date: 2015-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails