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 0fc79d1219
commit 1fd7dbe14b
2 changed files with 20 additions and 12 deletions

View File

@ -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.

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) {