diff --git a/apps/backend/src/api/routes/analytics.controller.ts b/apps/backend/src/api/routes/analytics.controller.ts
index d7eccbba..35d4913a 100644
--- a/apps/backend/src/api/routes/analytics.controller.ts
+++ b/apps/backend/src/api/routes/analytics.controller.ts
@@ -16,6 +16,7 @@ import { ApiTags } from '@nestjs/swagger';
import { IntegrationService } from '@gitroom/nestjs-libraries/database/prisma/integrations/integration.service';
import { IntegrationManager } from '@gitroom/nestjs-libraries/integrations/integration.manager';
import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service';
+import { RefreshToken } from '@gitroom/nestjs-libraries/integrations/social.abstract';
@ApiTags('Analytics')
@Controller('/analytics')
@@ -104,22 +105,29 @@ export class AnalyticsController {
}
if (integrationProvider.analytics) {
- const loadAnalytics = await integrationProvider.analytics(
- getIntegration.internalId,
- getIntegration.token,
- +date
- );
- await ioRedis.set(
- `integration:${org.id}:${integration}:${date}`,
- JSON.stringify(loadAnalytics),
- 'EX',
- !process.env.NODE_ENV || process.env.NODE_ENV === 'development'
- ? 1
- : 3600
- );
- return loadAnalytics;
+ try {
+ const loadAnalytics = await integrationProvider.analytics(
+ getIntegration.internalId,
+ getIntegration.token,
+ +date
+ );
+ await ioRedis.set(
+ `integration:${org.id}:${integration}:${date}`,
+ JSON.stringify(loadAnalytics),
+ 'EX',
+ !process.env.NODE_ENV || process.env.NODE_ENV === 'development'
+ ? 1
+ : 3600
+ );
+ return loadAnalytics;
+ } catch (e) {
+ if (e instanceof RefreshToken) {
+ await this._integrationService.disconnectChannel(org.id, getIntegration);
+ return [];
+ }
+ }
}
- return {};
+ return [];
}
}
diff --git a/apps/frontend/src/components/platform-analytics/platform.analytics.tsx b/apps/frontend/src/components/platform-analytics/platform.analytics.tsx
index f2af1506..b4cdc073 100644
--- a/apps/frontend/src/components/platform-analytics/platform.analytics.tsx
+++ b/apps/frontend/src/components/platform-analytics/platform.analytics.tsx
@@ -11,6 +11,7 @@ import { RenderAnalytics } from '@gitroom/frontend/components/platform-analytics
import { Select } from '@gitroom/react/form/select';
import { Button } from '@gitroom/react/form/button';
import { useRouter } from 'next/navigation';
+import { useToaster } from '@gitroom/react/toaster/toaster';
const allowedIntegrations = [
'facebook',
@@ -19,7 +20,7 @@ const allowedIntegrations = [
// 'tiktok',
'youtube',
'pinterest',
- 'threads'
+ 'threads',
];
export const PlatformAnalytics = () => {
@@ -27,7 +28,8 @@ export const PlatformAnalytics = () => {
const router = useRouter();
const [current, setCurrent] = useState(0);
const [key, setKey] = useState(7);
-
+ const [refresh, setRefresh] = useState(false);
+ const toaster = useToaster();
const load = useCallback(async () => {
const int = (await (await fetch('/integrations/list')).json()).integrations;
return int.filter((f: any) => allowedIntegrations.includes(f.identifier));
@@ -127,7 +129,7 @@ export const PlatformAnalytics = () => {
You have to add Social Media channels
- Supported: {allowedIntegrations.map(p => capitalize(p)).join(', ')}
+ Supported: {allowedIntegrations.map((p) => capitalize(p)).join(', ')}