@@ -123,21 +123,32 @@ def self.create(config:, endpoints:, log:)
123123 content_type "application/json"
124124 response . to_json
125125 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
127133 if defined? ( rack_env )
128134 Core ::PluginLoader . lifecycle_plugins . each do |plugin |
129135 plugin . on_error ( e , rack_env )
130136 end
131137 end
132138
133- log . error ( "an error occuring during the processing of a webhook event - #{ e . message } " )
139+ # construct a standardized error response
134140 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" ,
137143 request_id :
138144 }
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 )
141152 content_type "application/json"
142153 error_response . to_json
143154 end
0 commit comments