1
votes

Using mirth version 3.8.1. I've set up an alert for a channel's errors. When errors come from the destination transformer (which is Javascript), the alert is able to access the {messageId} variable and pull the correct id. However, when an error originates in the Javascript-based database writer, the alert just returns '{messageId}' instead of the value.

I tried a bunch of things... The global map is accessible from the alert, but putting a message id in there would get overwritten by another processing thread. Other destination types - http sender, tcp sender, channel writer, and even a non-javascript-based database writer destination all work.

I even stripped the database writer code down to just:

var dbConn;
dbConn = DatabaseConnectionFactory.createDatabaseConnection('com.mysql.cj.jdbc.Driver','jdbc:mysql://host:port/dbname','','');

Do I just have to raise specific exceptions within the db writer code and raise alerts when those exceptions are hit, and send the message id in the error string?

1
Are you building the query to write to your database using the JS flavor or the plain flavor? In either case please post how you are building your query. You likely are not using the correct substitution syntax for messageId.Freiheit

1 Answers

1
votes

You stumbled across a bug. I opened an issue and a fix.

If not for another bug that also neglects to provide the messageId, you should be able to use alerts.sendAlert('Custom Error Message'). alerts is an instance of AlertSender from the User API that mirth creates for you. I created a fix for that as well.

The only workaround I know of at this time to manually send an alert that includes the messageId is to call the EventController directly. The caveat is that this is technically not supported as part of a public API and usage could break in future versions without notice.

com.mirth.connect.server.controllers.ControllerFactory
    .getFactory()
    .createEventController()
    .dispatchEvent(new com.mirth.connect.donkey.server.event.ErrorEvent(
        connectorMessage.getChannelId(),
        connectorMessage.getMetaDataId(),
        connectorMessage.getMessageId(),
        com.mirth.connect.donkey.model.event.ErrorEventType.USER_DEFINED_TRANSFORMER,
        connectorMessage.getConnectorName(),
        null, /* connectorType */
        'A TEST ERROR MESSAGE',
        null /* throwable */
    )
);

This will work as written from a filter, transformer, Javascript Writer, or Database Writer in javascript mode. In other contexts, connectorMessage won't be defined and you'll have to provide some of those values in a different way. If you don't need the messageId and don't want to throw an exception, just use alerts.sendAlert(errorMessage) since that doesn't require calling unsupported internal classes.