dislogger 0.1.9 → 0.2.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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a274a53633279d495fd56b23a36c52730b7ca8e8c848f918e88be497b3d1dcf
4
- data.tar.gz: 7fb1ce90ab63bbff72470682564c11772d5985e32195c46681daa8daf95c83ac
3
+ metadata.gz: 40772178fe1446aaa2cc9bafcb10f11815e3416ad6a7b294dfbd69e9c153c338
4
+ data.tar.gz: e6e2d4e174ae770eff2b0be41cd9364a6f81606b393061379b168a23eb60fbf8
5
5
  SHA512:
6
- metadata.gz: 64dc81ec91e4c71e6e168aadd71ab5a7d6abd4a632a7f192a7373cf47a816a4365f232bcf337b834c29c12a1abba3c71fd660305e2e8a66bde392b4d24342f9a
7
- data.tar.gz: 2f55c155f9158f0252599b34353546d65bb14b9ea447efb35ce9cc59ea9b0a58a05777775cdfc32a352065eb42d9026c169f3cf4445d01a4ca767f3be3b690da
6
+ metadata.gz: 8bd268340561e183ef3668cee56ea2ca964d4c2a9b70571a7d2a9b683e57199be8444191284ff1a358167002acccefd57d7abe607594c2adbcf08703c9afa484
7
+ data.tar.gz: bbfbeed87f691bfa3d1f7049a5873d16f938fbd5b019dc71f04eb4024e1be59fb3fe5b65e77de547560df35fb2adeb63f1fbe14934f0679172c0aa0b03a69497
@@ -13,7 +13,7 @@ module Dislogger
13
13
  @discord_webhook_url = nil
14
14
  @bot_username = 'Error Logger'
15
15
  @backtrace_lines_limit = 5
16
- @enabled_environments = %w[production staging development]
16
+ @enabled_environments = %w[production staging]
17
17
  @environment = nil
18
18
  @error_color_map = {
19
19
  500 => 15158332, # Red for server errors
@@ -8,24 +8,110 @@ module Dislogger
8
8
 
9
9
  included do
10
10
  if ancestors.include?(ActionController::API) || ancestors.include?(ActionController::Base)
11
+ # System and Runtime Errors
11
12
  rescue_from Exception, with: :handle_exception
12
13
  rescue_from StandardError, with: :handle_internal_server_error
14
+ rescue_from RuntimeError, with: :handle_runtime_error
15
+ rescue_from SystemStackError, with: :handle_stack_error
16
+ rescue_from NoMemoryError, with: :handle_memory_error
17
+ rescue_from SystemCallError, with: :handle_system_error
18
+ rescue_from SignalException, with: :handle_signal_error
19
+ rescue_from ScriptError, with: :handle_script_error
20
+
21
+ # Database Errors
13
22
  rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found
14
23
  rescue_from ActiveRecord::RecordInvalid, with: :handle_unprocessable_entity
24
+ rescue_from ActiveRecord::RecordNotUnique, with: :handle_conflict
25
+ rescue_from ActiveRecord::ConnectionTimeoutError, with: :handle_timeout
26
+ rescue_from ActiveRecord::InvalidForeignKey, with: :handle_foreign_key_error
27
+ rescue_from ActiveRecord::ReadOnlyRecord, with: :handle_forbidden
28
+ rescue_from ActiveRecord::StaleObjectError, with: :handle_conflict
29
+
30
+ # Controller and Routing Errors
15
31
  rescue_from ActionController::ParameterMissing, with: :handle_unprocessable_entity
32
+ rescue_from ActionController::InvalidAuthenticityToken, with: :handle_unauthorized
33
+ rescue_from ActionController::UnknownFormat, with: :handle_not_acceptable
34
+ rescue_from ActionController::UrlGenerationError, with: :handle_bad_request
35
+ rescue_from ActionController::RoutingError, with: :handle_not_found
36
+ rescue_from AbstractController::ActionNotFound, with: :handle_not_found
37
+
38
+ # Authorization Errors
16
39
  rescue_from Pundit::NotAuthorizedError, with: :handle_forbidden if defined?(Pundit)
17
40
  rescue_from CanCan::AccessDenied, with: :handle_forbidden if defined?(CanCan)
41
+
42
+ # Common Ruby Errors
43
+ rescue_from NameError, with: :handle_internal_server_error
44
+ rescue_from NoMethodError, with: :handle_internal_server_error
45
+ rescue_from ArgumentError, with: :handle_bad_request
46
+ rescue_from TypeError, with: :handle_internal_server_error
47
+ rescue_from LoadError, with: :handle_internal_server_error
48
+ rescue_from SyntaxError, with: :handle_internal_server_error
49
+ rescue_from Timeout::Error, with: :handle_timeout
18
50
  end
19
51
  end
20
52
 
21
53
  private
22
54
 
23
55
  def handle_exception(exception)
24
- Rails.logger.error("Dislogger caught exception: #{exception.class.name} - #{exception.message}")
25
- Rails.logger.error(exception.backtrace.join("\n")) if exception.backtrace
56
+ # Log detailed error information
57
+ Rails.logger.error("[Dislogger] Unexpected error caught: #{exception.class.name}")
58
+ Rails.logger.error("[Dislogger] Message: #{exception.message}")
59
+ Rails.logger.error("[Dislogger] Backtrace:\n#{exception.backtrace.join("\n")}") if exception.backtrace
60
+
61
+ notify_and_render_error(
62
+ message: "An unexpected error occurred: #{exception.class.name} - #{exception.message}",
63
+ status: :internal_server_error,
64
+ backtrace: exception.backtrace,
65
+ details: {
66
+ error_class: exception.class.name,
67
+ message: exception.message
68
+ }
69
+ )
70
+ end
71
+
72
+ def handle_runtime_error(exception)
73
+ notify_and_render_error(
74
+ message: "Runtime error: #{exception.message}",
75
+ status: :internal_server_error,
76
+ backtrace: exception.backtrace
77
+ )
78
+ end
79
+
80
+ def handle_stack_error(exception)
81
+ notify_and_render_error(
82
+ message: "Stack overflow error: #{exception.message}",
83
+ status: :internal_server_error,
84
+ backtrace: exception.backtrace
85
+ )
86
+ end
87
+
88
+ def handle_memory_error(exception)
89
+ notify_and_render_error(
90
+ message: "Out of memory error: #{exception.message}",
91
+ status: :internal_server_error,
92
+ backtrace: exception.backtrace
93
+ )
94
+ end
95
+
96
+ def handle_system_error(exception)
97
+ notify_and_render_error(
98
+ message: "System error: #{exception.message}",
99
+ status: :internal_server_error,
100
+ backtrace: exception.backtrace
101
+ )
102
+ end
103
+
104
+ def handle_signal_error(exception)
105
+ notify_and_render_error(
106
+ message: "Signal error: #{exception.message}",
107
+ status: :internal_server_error,
108
+ backtrace: exception.backtrace
109
+ )
110
+ end
26
111
 
112
+ def handle_script_error(exception)
27
113
  notify_and_render_error(
28
- message: "#{exception.class.name}: #{exception.message}",
114
+ message: "Script error: #{exception.message}",
29
115
  status: :internal_server_error,
30
116
  backtrace: exception.backtrace
31
117
  )
@@ -39,7 +125,14 @@ module Dislogger
39
125
  end
40
126
 
41
127
  def handle_unprocessable_entity(exception)
42
- errors = exception.respond_to?(:record) ? exception.record.errors.full_messages : [exception.message]
128
+ errors = if exception.respond_to?(:record)
129
+ exception.record.errors.full_messages
130
+ elsif exception.respond_to?(:errors)
131
+ exception.errors
132
+ else
133
+ [exception.message]
134
+ end
135
+
43
136
  notify_and_render_error(
44
137
  message: 'Validation failed',
45
138
  status: :unprocessable_entity,
@@ -47,16 +140,59 @@ module Dislogger
47
140
  )
48
141
  end
49
142
 
143
+ def handle_conflict(exception)
144
+ notify_and_render_error(
145
+ message: exception.message || 'Resource conflict',
146
+ status: :conflict
147
+ )
148
+ end
149
+
150
+ def handle_timeout(exception)
151
+ notify_and_render_error(
152
+ message: exception.message || 'Request timeout',
153
+ status: :request_timeout
154
+ )
155
+ end
156
+
157
+ def handle_foreign_key_error(exception)
158
+ notify_and_render_error(
159
+ message: 'Cannot delete or update due to database constraint',
160
+ status: :unprocessable_entity,
161
+ details: [exception.message]
162
+ )
163
+ end
164
+
165
+ def handle_unauthorized(exception)
166
+ notify_and_render_error(
167
+ message: exception.message || 'Unauthorized access',
168
+ status: :unauthorized
169
+ )
170
+ end
171
+
50
172
  def handle_forbidden(exception)
51
173
  notify_and_render_error(
52
- message: exception.message.presence || 'You are not authorized to perform this action',
174
+ message: exception.message.presence || 'Access forbidden',
53
175
  status: :forbidden
54
176
  )
55
177
  end
56
178
 
179
+ def handle_not_acceptable(exception)
180
+ notify_and_render_error(
181
+ message: exception.message || 'Not acceptable',
182
+ status: :not_acceptable
183
+ )
184
+ end
185
+
186
+ def handle_bad_request(exception)
187
+ notify_and_render_error(
188
+ message: exception.message || 'Bad request',
189
+ status: :bad_request
190
+ )
191
+ end
192
+
57
193
  def handle_internal_server_error(exception)
58
194
  notify_and_render_error(
59
- message: exception.message || 'Internal Server Error',
195
+ message: exception.message || 'Internal server error',
60
196
  status: :internal_server_error,
61
197
  backtrace: exception.backtrace
62
198
  )
@@ -72,19 +208,35 @@ module Dislogger
72
208
  backtrace: backtrace
73
209
  )
74
210
 
75
- Rails.logger.info("Dislogger notification result: #{notification_result}") if defined?(Rails)
211
+ Rails.logger.info("[Dislogger] Notification result: #{notification_result}") if defined?(Rails)
76
212
 
77
- render_error(message, status, details)
213
+ render_error(message, status, error_details)
78
214
  end
79
215
 
80
216
  def render_error(message, status, details = nil)
81
217
  error_response = {
82
218
  status: status,
83
- message: message
219
+ message: message,
220
+ timestamp: Time.current.utc.iso8601
84
221
  }
85
222
  error_response[:details] = details if details
86
223
 
87
224
  render json: error_response, status: status
88
225
  end
226
+
227
+ private
228
+
229
+ def filter_sensitive_params(params_hash)
230
+ # List of sensitive parameters we don't want to show
231
+ sensitive_params = %w[password password_confirmation token api_key secret]
232
+
233
+ params_hash.deep_transform_values do |value|
234
+ if sensitive_params.any? { |param| value.to_s.include?(param) }
235
+ '[FILTERED]'
236
+ else
237
+ value
238
+ end
239
+ end
240
+ end
89
241
  end
90
242
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dislogger
4
- VERSION = "0.1.9"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dislogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nelson