[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';
|
||||
|
||||
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', () => {
|
||||
let service: MicrosoftGetMessageListService;
|
||||
|
||||
@ -12,18 +12,20 @@ import {
|
||||
MessageImportDriverExceptionCode,
|
||||
} 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 { MicrosoftHandleErrorService } from 'src/modules/messaging/message-import-manager/drivers/microsoft/services/microsoft-handle-error.service';
|
||||
import {
|
||||
GetFullMessageListResponse,
|
||||
GetPartialMessageListResponse,
|
||||
} from 'src/modules/messaging/message-import-manager/services/messaging-get-message-list.service';
|
||||
|
||||
// Microsoft API limit is 1000 messages per request on this endpoint
|
||||
const MESSAGING_MICROSOFT_USERS_MESSAGES_LIST_MAX_RESULT = 1000;
|
||||
// Microsoft API limit is 999 messages per request on this endpoint
|
||||
const MESSAGING_MICROSOFT_USERS_MESSAGES_LIST_MAX_RESULT = 999;
|
||||
|
||||
@Injectable()
|
||||
export class MicrosoftGetMessageListService {
|
||||
constructor(
|
||||
private readonly microsoftClientProvider: MicrosoftClientProvider,
|
||||
private readonly microsoftHandleErrorService: MicrosoftHandleErrorService,
|
||||
) {}
|
||||
|
||||
public async getFullMessageList(
|
||||
@ -54,7 +56,9 @@ export class MicrosoftGetMessageListService {
|
||||
|
||||
const pageIterator = new PageIterator(microsoftClient, response, callback);
|
||||
|
||||
await pageIterator.iterate();
|
||||
await pageIterator.iterate().catch((error) => {
|
||||
this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(error);
|
||||
});
|
||||
|
||||
return {
|
||||
messageExternalIds: messageExternalIds,
|
||||
@ -103,7 +107,9 @@ export class MicrosoftGetMessageListService {
|
||||
|
||||
const pageIterator = new PageIterator(microsoftClient, response, callback);
|
||||
|
||||
await pageIterator.iterate();
|
||||
await pageIterator.iterate().catch((error) => {
|
||||
this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(error);
|
||||
});
|
||||
|
||||
return {
|
||||
messageExternalIds,
|
||||
|
||||
@ -53,9 +53,7 @@ export class MicrosoftGetMessagesService {
|
||||
|
||||
return messages;
|
||||
} catch (error) {
|
||||
this.microsoftHandleErrorService.handleMicrosoftMessageListFetchError(
|
||||
error,
|
||||
);
|
||||
this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(error);
|
||||
|
||||
return [];
|
||||
}
|
||||
@ -81,7 +79,7 @@ export class MicrosoftGetMessagesService {
|
||||
|
||||
const messages = parsedResponses.map((response) => {
|
||||
if ('error' in response) {
|
||||
this.microsoftHandleErrorService.handleMicrosoftMessageListFetchError(
|
||||
this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(
|
||||
response.error,
|
||||
);
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import {
|
||||
|
||||
@Injectable()
|
||||
export class MicrosoftHandleErrorService {
|
||||
public handleMicrosoftMessageListFetchError(error: GraphError): void {
|
||||
public handleMicrosoftMessageFetchError(error: GraphError): void {
|
||||
if (error.statusCode === 401) {
|
||||
throw new MessageImportDriverException(
|
||||
'Unauthorized access to Microsoft Graph API',
|
||||
|
||||
Reference in New Issue
Block a user