Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
#287: Fix error message display
Browse files Browse the repository at this point in the history
  • Loading branch information
Peyman Aparviz committed Sep 26, 2018
1 parent 6a06be8 commit 0404abc
Showing 1 changed file with 42 additions and 36 deletions.
78 changes: 42 additions & 36 deletions integration/rocket-chat/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,22 +216,24 @@ function Smarti(options) {
// get RC's search provider
const spCallId = ddp.method("rocketchatSearch.getProvider", []);
ddp.on("result", (message) => {
if (message.error) {
log.error('Failed to get search provider:', message.error);
return;
} else if(message.id === spCallId) {
if(message.result) {
searchProvider = message.result;
log.debug('Search provider found: ', searchProvider);
if(searchProvider.key == "chatpalProvider") {
searchProviderSupported = true;
if(message.id === spCallId) {
if (message.error) {
log.error('Failed to get search provider:', message.error);
return;
} else {
if(message.result) {
searchProvider = message.result;
log.debug('Search provider found: ', searchProvider);
if(searchProvider.key == "chatpalProvider") {
searchProviderSupported = true;
} else {
searchProviderSupported = false;
log.info(`Search provider ${searchProvider.key} is not supported!`);
}
} else {
searchProviderSupported = false;
log.info(`Search provider ${searchProvider.key} is not supported!`);
log.info('Search provider is not active!');
return;
}
} else {
log.info('Search provider is not active!');
return;
}
}
});
Expand All @@ -240,17 +242,19 @@ function Smarti(options) {
log.debug('init -> get conversation ID for channel', options.channel);
const lastConvCallId = ddp.method("getConversationId", [options.channel]);
ddp.on("result", (message) => {
if (message.error) {
log.error('Failed to get conversation ID:', message.error);
return failure({i18nObj: {code:'smarti.result.conversation-not-found'}});
} else if(message.id === lastConvCallId) {
if(message.result) {
// conversation ID found for channel -> fetch conversation results
conversationId = message.result;
getConversation(message.result, failure);
if(message.id === lastConvCallId) {
if (message.error) {
log.error('Failed to get conversation ID:', message.error);
return failure({i18nObj: {code: 'smarti.result.conversation-not-found'}});
} else {
log.debug('init -> conversation ID not found for channel:', options.channel);
return failure({i18nObj: {code:'smarti.result.conversation-not-found'}});
if (message.result) {
// conversation ID found for channel -> fetch conversation results
conversationId = message.result;
getConversation(message.result, failure);
} else {
log.debug('init -> conversation ID not found for channel:', options.channel);
return failure({i18nObj: {code: 'smarti.result.conversation-not-found'}});
}
}
}
});
Expand Down Expand Up @@ -288,20 +292,22 @@ function Smarti(options) {
log.debug('Fetch results for conversation with ID:', conversationId);
const msgid = ddp.method("getConversation", [conversationId]);
ddp.on("result", (message) => {
if (message.error) {
log.error('Failed to get conversation:', message.error);
if(failure) failure({i18nObj: {code:'smarti.result.conversation-not-found'}});
} else if(message.id === msgid) {
if(message.result && message.result != "null") {
if(message.result.error) {
log.error('Server-side error:', message.result.error);
//const errorCode = message.result.error.code || message.result.error.response && message.result.error.response.statusCode;
if(failure) failure({i18nObj: {code:'smarti.result.conversation-not-found'}});
if(message.id === msgid) {
if (message.error) {
log.error('Failed to get conversation:', message.error);
if (failure) failure({i18nObj: {code: 'smarti.result.conversation-not-found'}});
} else {
if (message.result && message.result != "null") {
if (message.result.error) {
log.error('Server-side error:', message.result.error);
//const errorCode = message.result.error.code || message.result.error.response && message.result.error.response.statusCode;
if (failure) failure({i18nObj: {code: 'smarti.result.conversation-not-found'}});
} else {
pubsub('smarti.data').publish(message.result);
}
} else {
pubsub('smarti.data').publish(message.result);
log.info(`Conversation fetch returned no results. Expecting async response... (${conversationId})`);
}
} else {
log.info(`Conversation fetch returned no results. Expecting async response... (${conversationId})`);
}
}
});
Expand Down

0 comments on commit 0404abc

Please sign in to comment.