Skip to content

Commit

Permalink
Fix platform event connection error messages
Browse files Browse the repository at this point in the history
Improved error message when a connection could not be established

ensure selected event is cleared out on org change
  • Loading branch information
paustint committed Dec 18, 2023
1 parent 909462c commit c62e224
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css } from '@emotion/react';
import { TITLES } from '@jetstream/shared/constants';
import { useTitle } from '@jetstream/shared/ui-utils';
import { useNonInitialEffect, useTitle } from '@jetstream/shared/ui-utils';
import { SplitWrapper as Split } from '@jetstream/splitjs';
import { ListItem, ListItemGroup, SalesforceOrgUi } from '@jetstream/types';
import { AutoFullHeightContainer } from '@jetstream/ui';
Expand Down Expand Up @@ -46,6 +46,10 @@ export const PlatformEventMonitor: FunctionComponent<PlatformEventMonitorProps>
};
}, []);

useNonInitialEffect(() => {
setSelectedPublishEvent(null);
}, [selectedOrg]);

useEffect(() => {
const subscriptionEvents: ListItemGroup<string, PlatformEventObject>[] = [
{
Expand Down Expand Up @@ -123,7 +127,7 @@ export const PlatformEventMonitor: FunctionComponent<PlatformEventMonitorProps>
const hasErrorOrNoEvents = !hasPlatformEvents || platformEventFetchError;

return (
<AutoFullHeightContainer className="slds-p-horizontal_x-small slds-scrollable_none">
<AutoFullHeightContainer className="slds-p-horizontal_x-small slds-scrollable_none" key={selectedOrg.uniqueId}>
{hasErrorOrNoEvents && (
<PlatformEventMonitorFetchEventStatus
serverUrl={serverUrl}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export interface EventMessage {
}

export interface EventMessageUnsuccessful extends EventMessage {
subscription: string;
error: string;
subscription?: string;
error?: string;
successful: false;
failure?: {
connectionType: string;
exception?: string;
reason?: string;
transport?: string;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,22 @@ export function usePlatformEvent({ selectedOrg }: { selectedOrg: SalesforceOrgUi
);

const handleSubscribeError = useCallback((message: EventMessageUnsuccessful) => {
logger.warn('[PLATFORM EVENT][ERROR] unsubscribing');
fireToast({ type: 'error', message: `Error subscribing to event: ${message.subscription}. ${message.error}` });
setMessagesByChannel((item) => {
return Object.keys(item)
.filter((key) => key !== message.subscription)
.reduce((output: MessagesByChannel, key) => {
output[key] = item[key];
return output;
}, {});
});
logger.warn('[PLATFORM EVENT][ERROR]', message);
if (message.subscription) {
fireToast({ type: 'error', message: `Error subscribing to event: ${message.subscription}. ${message.error}` });
setMessagesByChannel((item) => {
return Object.keys(item)
.filter((key) => key !== message.subscription)
.reduce((output: MessagesByChannel, key) => {
output[key] = item[key];
return output;
}, {});
});
} else if (message.channel === '/meta/handshake') {
fireToast({ type: 'error', message: `Error subscribing to event: ${message.failure?.reason || 'Unknown reason'}.` });
} else {
fireToast({ type: 'error', message: `There was an unknown error subscribing to the event` });
}
}, []);

const subscribe = useCallback(
Expand Down

0 comments on commit c62e224

Please sign in to comment.