From 59d5376f60d60e55b221a8548d92fe767e77deec Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Mon, 9 Mar 2020 14:53:00 +0100 Subject: [PATCH] Handle native GraphQLErrors --- client/src/pages/login-local.vue | 20 ++++++++++---------- client/src/pages/login.vue | 21 +++++++++++---------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/client/src/pages/login-local.vue b/client/src/pages/login-local.vue index 5500bde8..0105e224 100644 --- a/client/src/pages/login-local.vue +++ b/client/src/pages/login-local.vue @@ -103,22 +103,22 @@ export default { if (localLogin.success) { const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/' that.$router.push(redirectUrl); - } else { - const firstError = localLogin.errors[0]; - switch (firstError.field) { - case 'invalid_credentials': - that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.'; - break; - case 'license_inactive': - that.loginError = 'Ihre Lizenz ist nicht mehr aktiv.'; - break; - } } } catch (e) { console.warn(e); that.loginError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'; } } + }).catch(error => { + const firstError = error.graphQLErrors[0]; + switch (firstError.message) { + case 'invalid_credentials': + that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.'; + break; + case 'license_inactive': + that.loginError = 'Ihre Lizenz ist nicht mehr aktiv.'; + break; + } }); } }); diff --git a/client/src/pages/login.vue b/client/src/pages/login.vue index 3fbb38d8..eb48a294 100644 --- a/client/src/pages/login.vue +++ b/client/src/pages/login.vue @@ -95,22 +95,23 @@ export default { const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/'; that.$router.push(redirectUrl); } - } else { - const firstError = login.errors[0]; - switch (firstError.field) { - case 'invalid_credentials': - that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.'; - break; - case 'no_valid_license': - this.$router.push({name: 'licenseActivation'}) - break; - } } } catch (e) { console.warn(e); that.loginError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'; } } + }) + .catch(errors => { + const firstError = errors.graphQLErrors[0]; + switch (firstError.message) { + case 'invalid_credentials': + that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.'; + break; + case 'no_valid_license': + this.$router.push({name: 'licenseActivation'}) + break; + } }); }, resetForm() {