Handle update identity with bad identity username

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-11-05 15:03:35 +01:00
parent f91f8ab926
commit 08dab070e7
2 changed files with 20 additions and 12 deletions

View File

@@ -134,9 +134,14 @@ export default class EditIdentity extends Vue {
this.resetFields();
this.identityName = val;
const identity = await this.getIdentity();
if (this.identityName) {
this.identity = await this.getIdentity();
if (!identity) {
return await this.$router.push({ name: 'CreateIdentity' });
}
if (this.identityName && identity) {
this.identity = identity;
this.avatarFile = await buildFileFromIPicture(this.identity.avatar);
}
@@ -280,15 +285,18 @@ export default class EditIdentity extends Vue {
});
}
private async getIdentity() {
const result = await this.$apollo.query({
query: FETCH_PERSON,
variables: {
username: this.identityName,
},
});
return new Person(result.data.fetchPerson);
private async getIdentity(): Promise<Person|null> {
try {
const result = await this.$apollo.query({
query: FETCH_PERSON,
variables: {
username: this.identityName,
},
});
return new Person(result.data.fetchPerson);
} catch (e) {
return null;
}
}
private handleError(err: any) {