twentyhq / twenty

Building a modern alternative to Salesforce, powered by the community.
https://twenty.com
GNU Affero General Public License v3.0
15.52k stars 1.62k forks source link

Refactor messaging error handling to create generic messaging errors #6257

Open bosiraphael opened 1 month ago

bosiraphael commented 1 month ago

Scope & Context

Refactor messaging error handling to create generic messaging errors.

Technical inputs

Do as in

greptile-apps[bot] commented 1 month ago
  1. 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';
    }
    }
  2. 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);
    }
  }
}

References

/packages/twenty-server/src/modules/messaging/common/services /packages/twenty-server/src/modules/messaging/message-import-manager/drivers/gmail/services

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant. [Ask Greptile](https://app.greptile.com/chat/github/twentyhq/twenty/main) ยท [Edit Issue Bot Settings](https://app.greptile.com/apps/github)