[Microsoft Outlook] fix + error handling (#9696)
- bettter error handling - small fix in the amount of items Microsoft graph api accepts
This commit is contained in:
@ -10,7 +10,7 @@ import { MicrosoftGetMessageListService } from './microsoft-get-message-list.ser
|
|||||||
import { MicrosoftHandleErrorService } from './microsoft-handle-error.service';
|
import { MicrosoftHandleErrorService } from './microsoft-handle-error.service';
|
||||||
|
|
||||||
const refreshToken = 'replace-with-your-refresh-token';
|
const refreshToken = 'replace-with-your-refresh-token';
|
||||||
const syncCursor = 'replace-with-your-sync-cursor';
|
const syncCursor = `replace-with-your-sync-cursor`;
|
||||||
|
|
||||||
xdescribe('Microsoft dev tests : get message list service', () => {
|
xdescribe('Microsoft dev tests : get message list service', () => {
|
||||||
let service: MicrosoftGetMessageListService;
|
let service: MicrosoftGetMessageListService;
|
||||||
|
|||||||
@ -12,18 +12,20 @@ import {
|
|||||||
MessageImportDriverExceptionCode,
|
MessageImportDriverExceptionCode,
|
||||||
} from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception';
|
} from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception';
|
||||||
import { MicrosoftClientProvider } from 'src/modules/messaging/message-import-manager/drivers/microsoft/providers/microsoft-client.provider';
|
import { MicrosoftClientProvider } from 'src/modules/messaging/message-import-manager/drivers/microsoft/providers/microsoft-client.provider';
|
||||||
|
import { MicrosoftHandleErrorService } from 'src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-handle-error.service';
|
||||||
import {
|
import {
|
||||||
GetFullMessageListResponse,
|
GetFullMessageListResponse,
|
||||||
GetPartialMessageListResponse,
|
GetPartialMessageListResponse,
|
||||||
} from 'src/modules/messaging/message-import-manager/services/messaging-get-message-list.service';
|
} from 'src/modules/messaging/message-import-manager/services/messaging-get-message-list.service';
|
||||||
|
|
||||||
// Microsoft API limit is 1000 messages per request on this endpoint
|
// Microsoft API limit is 999 messages per request on this endpoint
|
||||||
const MESSAGING_MICROSOFT_USERS_MESSAGES_LIST_MAX_RESULT = 1000;
|
const MESSAGING_MICROSOFT_USERS_MESSAGES_LIST_MAX_RESULT = 999;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MicrosoftGetMessageListService {
|
export class MicrosoftGetMessageListService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly microsoftClientProvider: MicrosoftClientProvider,
|
private readonly microsoftClientProvider: MicrosoftClientProvider,
|
||||||
|
private readonly microsoftHandleErrorService: MicrosoftHandleErrorService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public async getFullMessageList(
|
public async getFullMessageList(
|
||||||
@ -54,7 +56,9 @@ export class MicrosoftGetMessageListService {
|
|||||||
|
|
||||||
const pageIterator = new PageIterator(microsoftClient, response, callback);
|
const pageIterator = new PageIterator(microsoftClient, response, callback);
|
||||||
|
|
||||||
await pageIterator.iterate();
|
await pageIterator.iterate().catch((error) => {
|
||||||
|
this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(error);
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messageExternalIds: messageExternalIds,
|
messageExternalIds: messageExternalIds,
|
||||||
@ -103,7 +107,9 @@ export class MicrosoftGetMessageListService {
|
|||||||
|
|
||||||
const pageIterator = new PageIterator(microsoftClient, response, callback);
|
const pageIterator = new PageIterator(microsoftClient, response, callback);
|
||||||
|
|
||||||
await pageIterator.iterate();
|
await pageIterator.iterate().catch((error) => {
|
||||||
|
this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(error);
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messageExternalIds,
|
messageExternalIds,
|
||||||
|
|||||||
@ -53,9 +53,7 @@ export class MicrosoftGetMessagesService {
|
|||||||
|
|
||||||
return messages;
|
return messages;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.microsoftHandleErrorService.handleMicrosoftMessageListFetchError(
|
this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(error);
|
||||||
error,
|
|
||||||
);
|
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -81,7 +79,7 @@ export class MicrosoftGetMessagesService {
|
|||||||
|
|
||||||
const messages = parsedResponses.map((response) => {
|
const messages = parsedResponses.map((response) => {
|
||||||
if ('error' in response) {
|
if ('error' in response) {
|
||||||
this.microsoftHandleErrorService.handleMicrosoftMessageListFetchError(
|
this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(
|
||||||
response.error,
|
response.error,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import {
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MicrosoftHandleErrorService {
|
export class MicrosoftHandleErrorService {
|
||||||
public handleMicrosoftMessageListFetchError(error: GraphError): void {
|
public handleMicrosoftMessageFetchError(error: GraphError): void {
|
||||||
if (error.statusCode === 401) {
|
if (error.statusCode === 401) {
|
||||||
throw new MessageImportDriverException(
|
throw new MessageImportDriverException(
|
||||||
'Unauthorized access to Microsoft Graph API',
|
'Unauthorized access to Microsoft Graph API',
|
||||||
|
|||||||
Reference in New Issue
Block a user