@@ -123,21 +123,32 @@ def self.create(config:, endpoints:, log:)
123
123
content_type "application/json"
124
124
response . to_json
125
125
rescue StandardError => e
126
- # Call lifecycle hooks: on_error
126
+ err_msg = "Error processing webhook event with handler: #{ handler_class_name } - #{ e . message } " \
127
+ "- request_id: #{ request_id } - path: #{ full_path } - method: #{ http_method } - " \
128
+ "backtrace: #{ e . backtrace . join ( "\n " ) } "
129
+ log . error ( err_msg )
130
+
131
+ # call lifecycle hooks: on_error if the rack_env is available
132
+ # if the rack_env is not available, it means the error occurred before we could build it
127
133
if defined? ( rack_env )
128
134
Core ::PluginLoader . lifecycle_plugins . each do |plugin |
129
135
plugin . on_error ( e , rack_env )
130
136
end
131
137
end
132
138
133
- log . error ( "an error occuring during the processing of a webhook event - #{ e . message } " )
139
+ # construct a standardized error response
134
140
error_response = {
135
- error : e . message ,
136
- code : determine_error_code ( e ) ,
141
+ error : "server_error" ,
142
+ message : "an unexpected error occurred while processing the request" ,
137
143
request_id :
138
144
}
139
- error_response [ :backtrace ] = e . backtrace unless config [ :production ]
140
- status error_response [ :code ]
145
+
146
+ # enrich the error response with details if not in production
147
+ error_response [ :backtrace ] = e . backtrace . join ( "\n " ) unless config [ :production ]
148
+ error_response [ :message ] = e . message unless config [ :production ]
149
+ error_response [ :handler ] = handler_class_name unless config [ :production ]
150
+
151
+ status determine_error_code ( e )
141
152
content_type "application/json"
142
153
error_response . to_json
143
154
end
0 commit comments