dislogger 0.1.9 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/dislogger/configuration.rb +1 -1
- data/lib/dislogger/error_handler.rb +156 -8
- data/lib/dislogger/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97423135b6a714bab43585a1d6ec3ae07941f723c3cbc6205d71ef4b539c84c8
|
4
|
+
data.tar.gz: ca58414d6d7c390da84de53779c32d98e74b7ab71abe30d6901d3fac5a969ff5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcd5f2b7c0efad0b186cb3ab1593d87b90180ed72d23a2398c11aae1d1f746822f01abd377b8b6022645b895b3b5b791bc547f39fdb21c0df31ca6f3f8d85b7b
|
7
|
+
data.tar.gz: 6a74e4249f314bf42b855ee1a07960aca720c36b0aebf891976cb493590e461913d00cb31b5ee59d0c556e59efaebb7faddeb8f0372e6dc51af9bc70170d3f0d
|
@@ -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
|
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,106 @@ 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
|
-
|
25
|
-
Rails.logger.error(exception.
|
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
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
def handle_runtime_error(exception)
|
69
|
+
notify_and_render_error(
|
70
|
+
message: "Runtime error: #{exception.message}",
|
71
|
+
status: :internal_server_error,
|
72
|
+
backtrace: exception.backtrace
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def handle_stack_error(exception)
|
77
|
+
notify_and_render_error(
|
78
|
+
message: "Stack overflow error: #{exception.message}",
|
79
|
+
status: :internal_server_error,
|
80
|
+
backtrace: exception.backtrace
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
def handle_memory_error(exception)
|
85
|
+
notify_and_render_error(
|
86
|
+
message: "Out of memory error: #{exception.message}",
|
87
|
+
status: :internal_server_error,
|
88
|
+
backtrace: exception.backtrace
|
89
|
+
)
|
90
|
+
end
|
26
91
|
|
92
|
+
def handle_system_error(exception)
|
27
93
|
notify_and_render_error(
|
28
|
-
message: "
|
94
|
+
message: "System error: #{exception.message}",
|
95
|
+
status: :internal_server_error,
|
96
|
+
backtrace: exception.backtrace
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
def handle_signal_error(exception)
|
101
|
+
notify_and_render_error(
|
102
|
+
message: "Signal error: #{exception.message}",
|
103
|
+
status: :internal_server_error,
|
104
|
+
backtrace: exception.backtrace
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
def handle_script_error(exception)
|
109
|
+
notify_and_render_error(
|
110
|
+
message: "Script error: #{exception.message}",
|
29
111
|
status: :internal_server_error,
|
30
112
|
backtrace: exception.backtrace
|
31
113
|
)
|
@@ -39,7 +121,14 @@ module Dislogger
|
|
39
121
|
end
|
40
122
|
|
41
123
|
def handle_unprocessable_entity(exception)
|
42
|
-
errors = exception.respond_to?(:record)
|
124
|
+
errors = if exception.respond_to?(:record)
|
125
|
+
exception.record.errors.full_messages
|
126
|
+
elsif exception.respond_to?(:errors)
|
127
|
+
exception.errors
|
128
|
+
else
|
129
|
+
[exception.message]
|
130
|
+
end
|
131
|
+
|
43
132
|
notify_and_render_error(
|
44
133
|
message: 'Validation failed',
|
45
134
|
status: :unprocessable_entity,
|
@@ -47,16 +136,59 @@ module Dislogger
|
|
47
136
|
)
|
48
137
|
end
|
49
138
|
|
139
|
+
def handle_conflict(exception)
|
140
|
+
notify_and_render_error(
|
141
|
+
message: exception.message || 'Resource conflict',
|
142
|
+
status: :conflict
|
143
|
+
)
|
144
|
+
end
|
145
|
+
|
146
|
+
def handle_timeout(exception)
|
147
|
+
notify_and_render_error(
|
148
|
+
message: exception.message || 'Request timeout',
|
149
|
+
status: :request_timeout
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
153
|
+
def handle_foreign_key_error(exception)
|
154
|
+
notify_and_render_error(
|
155
|
+
message: 'Cannot delete or update due to database constraint',
|
156
|
+
status: :unprocessable_entity,
|
157
|
+
details: [exception.message]
|
158
|
+
)
|
159
|
+
end
|
160
|
+
|
161
|
+
def handle_unauthorized(exception)
|
162
|
+
notify_and_render_error(
|
163
|
+
message: exception.message || 'Unauthorized access',
|
164
|
+
status: :unauthorized
|
165
|
+
)
|
166
|
+
end
|
167
|
+
|
50
168
|
def handle_forbidden(exception)
|
51
169
|
notify_and_render_error(
|
52
|
-
message: exception.message.presence || '
|
170
|
+
message: exception.message.presence || 'Access forbidden',
|
53
171
|
status: :forbidden
|
54
172
|
)
|
55
173
|
end
|
56
174
|
|
175
|
+
def handle_not_acceptable(exception)
|
176
|
+
notify_and_render_error(
|
177
|
+
message: exception.message || 'Not acceptable',
|
178
|
+
status: :not_acceptable
|
179
|
+
)
|
180
|
+
end
|
181
|
+
|
182
|
+
def handle_bad_request(exception)
|
183
|
+
notify_and_render_error(
|
184
|
+
message: exception.message || 'Bad request',
|
185
|
+
status: :bad_request
|
186
|
+
)
|
187
|
+
end
|
188
|
+
|
57
189
|
def handle_internal_server_error(exception)
|
58
190
|
notify_and_render_error(
|
59
|
-
message: exception.message || 'Internal
|
191
|
+
message: exception.message || 'Internal server error',
|
60
192
|
status: :internal_server_error,
|
61
193
|
backtrace: exception.backtrace
|
62
194
|
)
|
@@ -72,7 +204,7 @@ module Dislogger
|
|
72
204
|
backtrace: backtrace
|
73
205
|
)
|
74
206
|
|
75
|
-
Rails.logger.info("Dislogger
|
207
|
+
Rails.logger.info("[Dislogger] Notification result: #{notification_result}") if defined?(Rails)
|
76
208
|
|
77
209
|
render_error(message, status, details)
|
78
210
|
end
|
@@ -80,11 +212,27 @@ module Dislogger
|
|
80
212
|
def render_error(message, status, details = nil)
|
81
213
|
error_response = {
|
82
214
|
status: status,
|
83
|
-
message: message
|
215
|
+
message: message,
|
216
|
+
timestamp: Time.current.utc.iso8601
|
84
217
|
}
|
85
218
|
error_response[:details] = details if details
|
86
219
|
|
87
220
|
render json: error_response, status: status
|
88
221
|
end
|
222
|
+
|
223
|
+
private
|
224
|
+
|
225
|
+
def filter_sensitive_params(params_hash)
|
226
|
+
# List of sensitive parameters we don't want to show
|
227
|
+
sensitive_params = %w[password password_confirmation token api_key secret]
|
228
|
+
|
229
|
+
params_hash.deep_transform_values do |value|
|
230
|
+
if sensitive_params.any? { |param| value.to_s.include?(param) }
|
231
|
+
'[FILTERED]'
|
232
|
+
else
|
233
|
+
value
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
89
237
|
end
|
90
238
|
end
|
data/lib/dislogger/version.rb
CHANGED