better logging errors in messages (#12136)
This commit is contained in:
+12
-1
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||
import { MicrosoftImportDriverException } from 'src/modules/messaging/message-import-manager/drivers/microsoft/exceptions/microsoft-import-driver.exception';
|
||||
@@ -8,6 +8,7 @@ import { isMicrosoftClientTemporaryError } from 'src/modules/messaging/message-i
|
||||
|
||||
@Injectable()
|
||||
export class MicrosoftFetchByBatchService {
|
||||
private readonly logger = new Logger(MicrosoftFetchByBatchService.name);
|
||||
constructor(
|
||||
private readonly microsoftClientProvider: MicrosoftClientProvider,
|
||||
) {}
|
||||
@@ -56,8 +57,18 @@ export class MicrosoftFetchByBatchService {
|
||||
typeof error.body === 'string' &&
|
||||
isMicrosoftClientTemporaryError(error.body)
|
||||
) {
|
||||
// TODO: remove this log once we catch better the error codes
|
||||
this.logger.error(
|
||||
`Error temporary (${error.code}) fetching messages for account ${connectedAccount.id.slice(0, 8)}`,
|
||||
);
|
||||
this.logger.log(error);
|
||||
throw new MicrosoftImportDriverException(error.body, error.code, 429);
|
||||
} else {
|
||||
// TODO: remove this log once we catch better the error codes
|
||||
this.logger.error(
|
||||
`Error unknown (${error.code}) fetching messages for account ${connectedAccount.id.slice(0, 8)}`,
|
||||
);
|
||||
this.logger.log(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
-1
@@ -51,7 +51,6 @@ xdescribe('Microsoft dev tests : get messages service', () => {
|
||||
const result = await service.getMessages(
|
||||
mockMessageIds,
|
||||
mockConnectedAccount,
|
||||
'workspace-1',
|
||||
);
|
||||
|
||||
expect(result).toHaveLength(1);
|
||||
|
||||
-11
@@ -28,10 +28,7 @@ export class MicrosoftGetMessagesService {
|
||||
async getMessages(
|
||||
messageIds: string[],
|
||||
connectedAccount: ConnectedAccountType,
|
||||
workspaceId: string,
|
||||
): Promise<MessageWithParticipants[]> {
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
const { batchResponses } =
|
||||
await this.microsoftFetchByBatchService.fetchAllByBatches(
|
||||
@@ -44,14 +41,6 @@ export class MicrosoftGetMessagesService {
|
||||
connectedAccount,
|
||||
);
|
||||
|
||||
const endTime = Date.now();
|
||||
|
||||
this.logger.log(
|
||||
`Messaging import for workspace ${workspaceId} and account ${
|
||||
connectedAccount.id
|
||||
} fetched ${messages.length} messages in ${endTime - startTime}ms`,
|
||||
);
|
||||
|
||||
return messages;
|
||||
} catch (error) {
|
||||
this.microsoftHandleErrorService.handleMicrosoftMessageFetchError(error);
|
||||
|
||||
+4
-1
@@ -1,3 +1,6 @@
|
||||
export const isMicrosoftClientTemporaryError = (body: string): boolean => {
|
||||
return body.includes('Unexpected token < in JSON at position');
|
||||
return (
|
||||
body.includes('Unexpected token < in JSON at position') ||
|
||||
body.includes('ApplicationThrottled 429 error')
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user