이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 9. Error handling
Errors in AMQ JavaScript can be handled by intercepting named events corresponding to AMQP protocol or connection errors.
9.1. Handling connection and protocol errors
You can handle protocol-level errors by intercepting the following events:
-
connection_error
-
session_error
-
sender_error
-
receiver_error
-
protocol_error
-
error
These events are fired whenever there is an error condition with the specific object that is in the event. After calling the error handler, the corresponding <object>_close
handler is also called.
The event
argument has an error
attribute for accessing the error object.
Example: Handling errors
container.on("error", function (event) { console.log("An error!", event.error); });
Because the close handlers are called in the event of any error, only the error itself needs to be handled within the error handler. Resource cleanup can be managed by close handlers. If there is no error handling that is specific to a particular object, it is typical to handle the general error
event and not have a more specific handler.
When reconnect is enabled and the remote server closes a connection with the amqp:connection:forced
condition, the client does not treat it as an error and thus does not fire the connection_error
event. The client instead begins the reconnection process.