diff --git a/packages/@webex/plugin-meetings/src/meetings/index.ts b/packages/@webex/plugin-meetings/src/meetings/index.ts index 6229462791b..dd0ade33a9f 100644 --- a/packages/@webex/plugin-meetings/src/meetings/index.ts +++ b/packages/@webex/plugin-meetings/src/meetings/index.ts @@ -1044,48 +1044,55 @@ export default class Meetings extends WebexPlugin { */ fetchUserPreferredWebexSite() { // @ts-ignore - return this.webex.people._getMe().then((me) => { - const isGuestUser = me.type === 'appuser'; - if (!isGuestUser) { - return this.request.getMeetingPreferences().then((res) => { - if (res) { - const preferredWebexSite = MeetingsUtil.parseDefaultSiteFromMeetingPreferences(res); - this.preferredWebexSite = preferredWebexSite; - // @ts-ignore - this.webex.internal.services._getCatalog().addAllowedDomains([preferredWebexSite]); - } + return this.webex.people + ._getMe() + .then((me) => { + const isGuestUser = me.type === 'appuser'; + if (!isGuestUser) { + return this.request.getMeetingPreferences().then((res) => { + if (res) { + const preferredWebexSite = MeetingsUtil.parseDefaultSiteFromMeetingPreferences(res); + this.preferredWebexSite = preferredWebexSite; + // @ts-ignore + this.webex.internal.services._getCatalog().addAllowedDomains([preferredWebexSite]); + } - // fall back to getting the preferred site from the user information - if (!this.preferredWebexSite) { - // @ts-ignore - return this.webex.internal.user - .get() - .then((user) => { - const preferredWebexSite = - user?.userPreferences?.userPreferencesItems?.preferredWebExSite; - if (preferredWebexSite) { - this.preferredWebexSite = preferredWebexSite; - // @ts-ignore - this.webex.internal.services - ._getCatalog() - .addAllowedDomains([preferredWebexSite]); - } else { - throw new Error('site not found'); - } - }) - .catch(() => { - LoggerProxy.logger.error( - 'Failed to fetch preferred site from user - no site will be set' - ); - }); - } + // fall back to getting the preferred site from the user information + if (!this.preferredWebexSite) { + // @ts-ignore + return this.webex.internal.user + .get() + .then((user) => { + const preferredWebexSite = + user?.userPreferences?.userPreferencesItems?.preferredWebExSite; + if (preferredWebexSite) { + this.preferredWebexSite = preferredWebexSite; + // @ts-ignore + this.webex.internal.services + ._getCatalog() + .addAllowedDomains([preferredWebexSite]); + } else { + throw new Error('site not found'); + } + }) + .catch(() => { + LoggerProxy.logger.error( + 'Failed to fetch preferred site from user - no site will be set' + ); + }); + } - return Promise.resolve(); - }); - } + return Promise.resolve(); + }); + } - return Promise.resolve(); - }); + return Promise.resolve(); + }) + .catch(() => { + LoggerProxy.logger.error( + 'Failed to retrieve user information. No preferredWebexSite will be set' + ); + }); } /** diff --git a/packages/@webex/plugin-meetings/test/unit/spec/meetings/index.js b/packages/@webex/plugin-meetings/test/unit/spec/meetings/index.js index 89a64498e36..545a05fbd97 100644 --- a/packages/@webex/plugin-meetings/test/unit/spec/meetings/index.js +++ b/packages/@webex/plugin-meetings/test/unit/spec/meetings/index.js @@ -2077,6 +2077,21 @@ describe('plugin-meetings', () => { ]); }); + it('should handle failure to get user information if scopes are insufficient', async () => { + loggerProxySpy = sinon.spy(LoggerProxy.logger, 'error'); + Object.assign(webex.people, { + _getMe: sinon.stub().returns(Promise.reject()), + }); + + await webex.meetings.fetchUserPreferredWebexSite(); + + assert.equal(webex.meetings.preferredWebexSite, ''); + assert.calledOnceWithExactly( + loggerProxySpy, + 'Failed to retrieve user information. No preferredWebexSite will be set' + ); + }); + const setup = ({me = { type: 'validuser'}, user} = {}) => { loggerProxySpy = sinon.spy(LoggerProxy.logger, 'error'); assert.deepEqual(webex.internal.services._getCatalog().getAllowedDomains(), []); @@ -2093,7 +2108,7 @@ describe('plugin-meetings', () => { Object.assign(webex.people, { _getMe: sinon.stub().returns(Promise.resolve(me)), - }); + }); }; it('should not call request.getMeetingPreferences if user is a guest', async () => {