Open bosiraphael opened 1 month ago
Create a new generic error class in packages/twenty-server/src/modules/messaging/common/errors/messaging-generic-error.ts
:
export class MessagingGenericError extends Error {
constructor(message: string) {
super(message);
this.name = 'MessagingGenericError';
}
}
Refactor MessagingErrorHandlingService
in packages/twenty-server/src/modules/messaging/common/services/messaging-error-handling.service.ts
to use the new generic error:
import { MessagingGenericError } from '../errors/messaging-generic-error';
@Injectable() export class MessagingErrorHandlingService { handleError(error: any) { throw new MessagingGenericError(error.message || 'An error occurred'); } }
3. Update all services in `packages/twenty-server/src/modules/messaging/common/services` to use `MessagingErrorHandlingService` for error handling. For example, in `MessagingFetchByBatchesService`:
```typescript
import { MessagingErrorHandlingService } from './messaging-error-handling.service';
@Injectable()
export class MessagingFetchByBatchesService {
constructor(private readonly errorHandlingService: MessagingErrorHandlingService) {}
async fetchMessages() {
try {
// existing logic
} catch (error) {
this.errorHandlingService.handleError(error);
}
}
}
/packages/twenty-server/src/modules/messaging/common/services /packages/twenty-server/src/modules/messaging/message-import-manager/drivers/gmail/services
Scope & Context
Refactor messaging error handling to create generic messaging errors.
Technical inputs
Do as in
packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-event-import-error-handling.service.ts
packages/twenty-server/src/modules/calendar/calendar-event-import-manager/drivers/google-calendar/services/google-calendar-get-events.service.ts