diff --git a/src/EventTypes.js b/src/EventTypes.js index 777e441f0097816aa574681a253a8759c6c82e70..b351791795d9ba15c7b8fe44cdf45404a10b1618 100644 --- a/src/EventTypes.js +++ b/src/EventTypes.js @@ -108,6 +108,10 @@ const EventTypes = { EVENT_DRAFT_MESSAGE_CREATE: 'message-draft-create-event', EVENT_DRAFT_MESSAGE_DELETED: 'message-draft-deleted-event', // Draft events END + + // Errors events START + EVENT_ERROR_SCHEDULE_MESSAGE: 'error-schedule-message-event', + // Errors events END }; Object.freeze(EventTypes); diff --git a/src/libs/bert/SignatureGenerator.bert.js b/src/libs/bert/SignatureGenerator.bert.js index dd11e0df3bfb82a0d76a9028b6af1a3158bfd313..3bda1801a8aba60bc135bd1f7d7ee7359a7840fc 100644 --- a/src/libs/bert/SignatureGenerator.bert.js +++ b/src/libs/bert/SignatureGenerator.bert.js @@ -1457,6 +1457,12 @@ const messageAckUtils = mapper( encMessageAck, ); +const errorsUtils = mapper( + lenerrors, + decerrors, + encerrors, +); + export { decode, encode, @@ -1478,4 +1484,5 @@ export { ackUtils, draftUtils, messageAckUtils, + errorsUtils, }; diff --git a/src/managers/MessagesManager.js b/src/managers/MessagesManager.js index 199dfeb1829bd3ce18d562fe6539c29502a771e6..5c396006b2687dcb98ccfa0239dadbbb93d98196 100644 --- a/src/managers/MessagesManager.js +++ b/src/managers/MessagesManager.js @@ -37,6 +37,7 @@ class MessagesManager { this._eventsHelper.subscribe(this._eventsHelper.buildInternalEventName('io'), this.processIncomingIo); this._eventsHelper.subscribe(this._eventsHelper.buildInternalEventName('draft'), this.processIncomingDraft); this._eventsHelper.subscribe(this._eventsHelper.buildInternalEventName('messageack'), this.processIncomingMessageAck); + this._eventsHelper.subscribe(this._eventsHelper.buildInternalEventName('errors'), this.processIncomingErrors); } /** @@ -1119,6 +1120,20 @@ class MessagesManager { } }; + processIncomingErrors = (event) => { + if (event && event.data && event.data.data && event.data.data.data) { + // GIE1 = Invalid Request Data - https://nynjadev.atlassian.net/wiki/spaces/SER/pages/229605485/Status+Codes + const response = event.data.data; + if (response.code && Array.isArray(response.code) && response.code[0] === 'GIE1') { + // Error in Scheduling a message + if (response.data.tup === 'Job') { + this._eventsHelper.notify(EventTypes.EVENT_ERROR_SCHEDULE_MESSAGE, response.data); + return; + } + } + } + }; + /** * Get mqtt connection or throw an exception * diff --git a/src/protocols/protocols.js b/src/protocols/protocols.js index 1bea5af29b51c0497353b570f46872747fae445e..909bb5780180154b0a185e79c624f27e53e59cbf 100644 --- a/src/protocols/protocols.js +++ b/src/protocols/protocols.js @@ -18,6 +18,7 @@ import { ackUtils, draftUtils, messageAckUtils, + errorsUtils, } from '../libs/bert/SignatureGenerator.bert'; import ProtocolHandler from './ProtocolHandler'; @@ -40,6 +41,7 @@ const extendedStar = () => new ProtocolHandler(extendedStarUtils); const ack = () => new ProtocolHandler(ackUtils); const draft = () => new ProtocolHandler(draftUtils); const messageAck = () => new ProtocolHandler(messageAckUtils); +const errors = () => new ProtocolHandler(errorsUtils); // var export must be in smallcaps because of isRequiredProtocolExists() export { @@ -62,4 +64,5 @@ export { ack, draft, messageAck as messageack, + errors, };