admin-test.resolver.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { Args, Mutation, Resolver } from '@nestjs/graphql';
  2. import { Allow, Permission, UserInputError } from '@vendure/core';
  3. import { SentryService } from '../sentry.service';
  4. import { ErrorTestService } from './error-test.service';
  5. declare const a: number;
  6. @Resolver()
  7. export class SentryAdminTestResolver {
  8. constructor(
  9. private sentryService: SentryService,
  10. private errorTestService: ErrorTestService,
  11. ) {}
  12. @Allow(Permission.SuperAdmin)
  13. @Mutation()
  14. async createTestError(@Args() args: { errorType: string }) {
  15. switch (args.errorType) {
  16. case 'UNCAUGHT_ERROR':
  17. return a / 10;
  18. case 'THROWN_ERROR':
  19. throw new UserInputError('SentryPlugin Test Error');
  20. case 'CAPTURED_ERROR':
  21. this.sentryService.captureException(new Error('SentryPlugin Direct error'));
  22. return true;
  23. case 'CAPTURED_MESSAGE':
  24. this.sentryService.captureMessage('Captured message');
  25. return true;
  26. case 'DATABASE_ERROR':
  27. await this.errorTestService.createDatabaseError();
  28. return true;
  29. }
  30. }
  31. }