From 05c81df68d06bfe67ffff194acdfa9fabb4d028f Mon Sep 17 00:00:00 2001 From: ccremer Date: Thu, 20 Apr 2023 13:25:39 +0200 Subject: [PATCH] Handle user not found error --- cypress/e2e/user.cy.ts | 1 + src/app/user/user-edit/user-edit.component.html | 7 +++++-- src/app/user/user-edit/user-edit.component.ts | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cypress/e2e/user.cy.ts b/cypress/e2e/user.cy.ts index b6eedb36..40d5fdca 100644 --- a/cypress/e2e/user.cy.ts +++ b/cypress/e2e/user.cy.ts @@ -183,6 +183,7 @@ describe('Test failures', () => { cy.intercept('GET', 'appuio-api/apis/appuio.io/v1/users/mig', { statusCode: 403, }); + setOrganization(cy); cy.visit('/user'); cy.get('#failure-message').should('contain.text', 'User settings could not be loaded.'); diff --git a/src/app/user/user-edit/user-edit.component.html b/src/app/user/user-edit/user-edit.component.html index fa02fb1c..5b8581b6 100644 --- a/src/app/user/user-edit/user-edit.component.html +++ b/src/app/user/user-edit/user-edit.component.html @@ -47,10 +47,13 @@ - + -
User settings could not be loaded.
+
+ User settings could not be loaded. + If you're a new user, please try again later, as your settings might take a while to initialize. +
diff --git a/src/app/user/user-edit/user-edit.component.ts b/src/app/user/user-edit/user-edit.component.ts index 23afc255..d29dd542 100644 --- a/src/app/user/user-edit/user-edit.component.ts +++ b/src/app/user/user-edit/user-edit.component.ts @@ -1,6 +1,6 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; -import { combineLatestWith, forkJoin, map, Observable, of } from 'rxjs'; +import { catchError, combineLatestWith, forkJoin, map, Observable, of } from 'rxjs'; import { MessageService, SelectItem } from 'primeng/api'; import { faSave, faWarning } from '@fortawesome/free-solid-svg-icons'; import { Organization } from '../../types/organization'; @@ -10,6 +10,7 @@ import { OrganizationCollectionService } from '../../store/organization-collecti import { OrganizationMembersCollectionService } from '../../store/organizationmembers-collection.service'; import { UserCollectionService } from '../../store/user-collection.service'; import { switchMap } from 'rxjs/operators'; +import { defaultIfStatusCode } from '../../store/kubernetes-collection.service'; @Component({ selector: 'app-user-edit', @@ -38,6 +39,7 @@ export class UserEditComponent implements OnInit { ngOnInit(): void { const userName = this.identityService.getUsername(); this.payload$ = this.userService.getByKeyMemoized(userName).pipe( + catchError(defaultIfStatusCode(this.userService.newUser(userName), [401, 403, 404])), switchMap((user) => { if (user.metadata.resourceVersion) { return of(user);