Microsoft Throtling error and wrongly types on our side (#11266)

This commit is contained in:
Guillim
2025-03-28 17:37:46 +01:00
committed by GitHub
parent 8e39585c0d
commit d9ac662302
5 changed files with 33 additions and 6 deletions

View File

@ -0,0 +1,10 @@
import { CustomException } from 'src/utils/custom-exception';
export class MicrosoftImportDriverException extends CustomException {
statusCode: number;
constructor(message: string, code: string, statusCode: number) {
super(message, code);
this.statusCode = statusCode;
this.code = code;
}
}

View File

@ -80,7 +80,7 @@ export class MicrosoftGetMessagesService {
const messages = parsedResponses.map((response) => {
if ('error' in response) {
this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(
this.microsoftHandleErrorService.throwMicrosoftBatchError(
response.error,
);
}

View File

@ -4,6 +4,7 @@ import {
MessageImportDriverException,
MessageImportDriverExceptionCode,
} from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception';
import { MicrosoftImportDriverException } from 'src/modules/messaging/message-import-manager/drivers/microsoft/exceptions/microsoft-import-driver.exception';
@Injectable()
export class MicrosoftHandleErrorService {
@ -29,9 +30,24 @@ export class MicrosoftHandleErrorService {
);
}
if (error.statusCode === 429) {
throw new MessageImportDriverException(
`Microsoft Graph API ${error.code} ${error.statusCode} error: ${error.message}`,
MessageImportDriverExceptionCode.TEMPORARY_ERROR,
);
}
throw new MessageImportDriverException(
`Microsoft driver error: ${error.message}`,
MessageImportDriverExceptionCode.UNKNOWN,
);
}
public throwMicrosoftBatchError(error: any): void {
throw new MicrosoftImportDriverException(
error.message,
error.code,
error.statusCode,
);
}
}

View File

@ -18,7 +18,8 @@ export enum MessageImportSyncStep {
FULL_MESSAGE_LIST_FETCH = 'FULL_MESSAGE_LIST_FETCH',
PARTIAL_MESSAGE_LIST_FETCH = 'PARTIAL_MESSAGE_LIST_FETCH',
FULL_OR_PARTIAL_MESSAGE_LIST_FETCH = 'FULL_OR_PARTIAL_MESSAGE_LIST_FETCH',
MESSAGES_IMPORT = 'MESSAGES_IMPORT',
MESSAGES_IMPORT_PENDING = 'MESSAGES_IMPORT_PENDING',
MESSAGES_IMPORT_ONGOING = 'MESSAGES_IMPORT_ONGOING',
}
@Injectable()
@ -94,7 +95,7 @@ export class MessageImportExceptionHandlerService {
workspaceId,
);
throw new MessageImportException(
`Unknown error occurred multiple times while importing messages for message channel ${messageChannel.id} in workspace ${workspaceId}`,
`Unknown temporary error occurred multiple times while importing messages for message channel ${messageChannel.id} in workspace ${workspaceId}`,
MessageImportExceptionCode.UNKNOWN,
);
}
@ -122,8 +123,8 @@ export class MessageImportExceptionHandlerService {
[messageChannel.id],
);
break;
case MessageImportSyncStep.MESSAGES_IMPORT:
case MessageImportSyncStep.MESSAGES_IMPORT_PENDING:
case MessageImportSyncStep.MESSAGES_IMPORT_ONGOING:
await this.messageChannelSyncStatusService.scheduleMessagesImport([
messageChannel.id,
]);

View File

@ -192,7 +192,7 @@ export class MessagingMessagesImportService {
await this.messageImportErrorHandlerService.handleDriverException(
error,
MessageImportSyncStep.MESSAGES_IMPORT,
MessageImportSyncStep.MESSAGES_IMPORT_ONGOING,
messageChannel,
workspaceId,
);