From 08dab070e7bd6791a4edc98e45957a4ff8b4d0de Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 5 Nov 2019 15:03:35 +0100 Subject: [PATCH] Handle update identity with bad identity username Signed-off-by: Thomas Citharel --- config/dev.exs | 2 +- .../views/Account/children/EditIdentity.vue | 30 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/config/dev.exs b/config/dev.exs index ac5f5a921..ce28a21d0 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -52,7 +52,7 @@ config :mobilizon, MobilizonWeb.Endpoint, # Do not include metadata nor timestamps in development logs config :logger, :console, format: "[$level] $message\n", level: :debug -config :mobilizon, Mobilizon.Service.Geospatial, service: Mobilizon.Service.Geospatial.Nominatim +config :mobilizon, Mobilizon.Service.Geospatial, service: Mobilizon.Service.Geospatial.GoogleMaps # Set a higher stacktrace during development. Avoid configuring such # in production as building large stacktraces may be expensive. diff --git a/js/src/views/Account/children/EditIdentity.vue b/js/src/views/Account/children/EditIdentity.vue index edcafe955..34052b0b7 100644 --- a/js/src/views/Account/children/EditIdentity.vue +++ b/js/src/views/Account/children/EditIdentity.vue @@ -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 { + 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) {