You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Handle errors that occur during request processing. Logs the error, closes any response body, invokes `rack.response_finished` callbacks, and returns an appropriate failure response.
139
+
#
140
+
# The `rack.response_finished` callbacks are invoked in reverse order of registration, as specified by the Rack specification. If a callback raises an exception, it is caught and logged, but does not prevent other callbacks from being invoked.
141
+
#
142
+
# @parameter env [Hash] The Rack environment hash.
143
+
# @parameter status [Integer | Nil] The HTTP status code, if available. May be `nil` if the error occurred before the application returned a response.
144
+
# @parameter headers [Hash | Nil] The response headers, if available. May be `nil` if the error occurred before the application returned a response.
145
+
# @parameter body [Object | Nil] The response body, if available. May be `nil` if the error occurred before the application returned a response.
146
+
# @parameter error [Exception] The exception that occurred during request processing.
147
+
# @returns [Protocol::HTTP::Response] A failure response representing the error.
148
+
defhandle_error(env,status,headers,body,error)
149
+
Console.error(self,"Error occurred during request processing:",error)
150
+
151
+
# Close the response body if it exists and supports closing.
152
+
body&.closeifbody.respond_to?(:close)
153
+
154
+
# Invoke `rack.response_finished` callbacks in reverse order of registration.
155
+
# This ensures that callbacks registered later are invoked first, matching the Rack specification.
# Rack 2 does not include `rack.response_finished` in the specification. However, if the application has set it, we will call the callbacks here as it would be extremely surprising to not do so.
0 commit comments