Skip to content

Commit

Permalink
Fix(Integration resolver): prevent project edit page from blocking wh…
Browse files Browse the repository at this point in the history
…en integration is missing
  • Loading branch information
samuelmbabhazi committed Feb 27, 2025
1 parent f0eb8e9 commit 9f67cc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion apps/gauzy/src/app/pages/projects/projects-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const routes: Routes = [
{
path: ':id',
data: {
allowMissingIntegration: true,
integration: IntegrationEnum.GITHUB, // Custom data associated with this route
relations: ['integration'],
selectors: {
Expand All @@ -56,8 +57,9 @@ const routes: Routes = [
},
resolve: {
project: ProjectResolver,
integration: IntegrationResolver
integration: IntegrationResolver || null
},

children: [
{
path: 'edit',
Expand Down
22 changes: 13 additions & 9 deletions packages/ui-core/core/src/lib/resolvers/integration.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject } from '@angular/core';
import { ActivatedRouteSnapshot, ResolveFn, Router } from '@angular/router';
import { catchError, Observable, of } from 'rxjs';
import { catchError, EMPTY, Observable, of } from 'rxjs';
import { IIntegrationTenant } from '@gauzy/contracts';
import { IntegrationsService, Store } from '../services';

Expand Down Expand Up @@ -41,17 +41,21 @@ export const IntegrationResolver: ResolveFn<Observable<IIntegrationTenant | bool

// Handle errors and redirect if an error occurs
return integration$.pipe(
catchError((error) => {
if (error.status === 403) {
console.warn('Access to integration is forbidden (403), continuing without integration data.');
return of(null);
catchError(() => {
if (route.data.allowMissingIntegration) {
return of(false);
}
console.error('Unexpected error in IntegrationResolver:', error);
return of(null);

// Redirect to the "new integration" page if an error occurs
_router.navigate(['/pages/integrations/new']);
// Return an empty observable to prevent further actions
return EMPTY;
})
);
} catch (error) {
console.error('Unexpected error in IntegrationResolver:', error);
return of(null);
// Handle any synchronous errors and redirect to "new integration" page
_router.navigate(['/pages/integrations/new']);
// Return an empty observable
return EMPTY;
}
};

0 comments on commit 9f67cc8

Please sign in to comment.