changeset 546:b91791664554

refac: Errorhandling and formatting Some code was made Prettier. Error messages does fallback to data in case data.message is ot present When a login error occurs, a toast is presenterefac: Errorhandling and formatting Some code was made Prettier. Error messages does fallback to data in case data.message is ot present When a login error occurs, a toast is presented
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 31 Aug 2018 11:12:09 +0200
parents 9d999d29c642
children b3f825c8445b
files client/src/components/Userdetail.vue client/src/views/Login.vue client/src/views/Users.vue
diffstat 3 files changed, 34 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/Userdetail.vue	Fri Aug 31 11:03:22 2018 +0200
+++ b/client/src/components/Userdetail.vue	Fri Aug 31 11:12:09 2018 +0200
@@ -2,8 +2,10 @@
   <div class="userdetails shadown fadeIn animated">
     <div class="card">
       <div class="card-header shadow-sm text-white bg-info mb-3">
-          {{ this.cardHeader }}
-        <span @click="closeDetailview" class="pull-right"><i class="fa fa-close"></i></span>
+        {{ this.cardHeader }}
+        <span @click="closeDetailview" class="pull-right">
+          <i class="fa fa-close"></i>
+        </span>
       </div>
       <div class="card-body">
         <form @submit.prevent="save">
@@ -11,7 +13,10 @@
             <div v-if="currentUser.isNew" class="form-group row">
               <label for="user">Username</label>
               <input type="user" :placeholder="userNamePlaceholder" class="form-control form-control-sm" id="user" aria-describedby="userHelp" v-model="currentUser.user">
-              <div v-show="errors.user" class="text-danger"><small><i class="fa fa-warning"></i> {{ errors.user }}</small></div>
+              <div v-show="errors.user" class="text-danger">
+                <small>
+                  <i class="fa fa-warning"></i> {{ errors.user }}</small>
+              </div>
             </div>
             <div class="form-group row">
               <label for="country">Country</label>
@@ -19,12 +24,18 @@
                 <option disabled value="">Please select one</option>
                 <option v-for="country in countries" v-bind:value="country" v-bind:key="country">{{country}}</option>
               </select>
-              <div v-show="errors.country" class="text-danger"><small><i class="fa fa-warning"></i> {{ errors.country }}</small></div>
+              <div v-show="errors.country" class="text-danger">
+                <small>
+                  <i class="fa fa-warning"></i> {{ errors.country }}</small>
+              </div>
             </div>
             <div class="form-group row">
               <label for="email">Email address</label>
               <input type="email" v-on:change="validateEmailaddress" class="form-control form-control-sm" id="email" aria-describedby="emailHelp" v-model="currentUser.email">
-              <div v-show="errors.email" class="text-danger"><small><i class="fa fa-warning"></i> {{ errors.email }}</small></div>
+              <div v-show="errors.email" class="text-danger">
+                <small>
+                  <i class="fa fa-warning"></i> {{ errors.email }}</small>
+              </div>
             </div>
             <div class="form-group row">
               <label for="role">Role</label>
@@ -34,28 +45,23 @@
                 <option value="waterway_admin">Waterway Admin</option>
                 <option value="waterway_user">Waterway User</option>
               </select>
-              <div v-show="errors.role" class="text-danger"><small><i class="fa fa-warning"></i> {{ errors.role }}</small></div>
+              <div v-show="errors.role" class="text-danger">
+                <small>
+                  <i class="fa fa-warning"></i> {{ errors.role }}</small>
+              </div>
             </div>
             <div class="form-group row">
-              <PasswordField @fieldchange="passwordChanged"
-                             :placeholder="passwordPlaceholder"
-                             :label="passwordLabel"
-                             :passworderrors="errors.password"
-              ></PasswordField>
+              <PasswordField @fieldchange="passwordChanged" :placeholder="passwordPlaceholder" :label="passwordLabel" :passworderrors="errors.password"></PasswordField>
             </div>
             <div class="form-group row">
-              <PasswordField @fieldchange="passwordReChanged"
-                             :placeholder="passwordRePlaceholder"
-                             :label="passwordReLabel"
-                             :passworderrors="errors.passwordre"
-              ></PasswordField>
+              <PasswordField @fieldchange="passwordReChanged" :placeholder="passwordRePlaceholder" :label="passwordReLabel" :passworderrors="errors.passwordre"></PasswordField>
             </div>
           </div>
           <div>
             <button type="submit" :disabled="submitted" class="shadow-sm btn btn-info pull-right">Submit</button>
           </div>
         </form>
-    </div>
+      </div>
     </div>
   </div>
 </template>
@@ -238,7 +244,7 @@
             const { status, data } = error.response;
             displayError({
               title: "Backend Error",
-              message: `${status}: ${data.message}`
+              message: `${status}: ${data.message || data}`
             });
           });
         })
@@ -247,7 +253,7 @@
           const { status, data } = error.response;
           displayError({
             title: "Error while saving user",
-            message: `${status}: ${data.message}`
+            message: `${status}: ${data.message || data}`
           });
         });
     }
--- a/client/src/views/Login.vue	Fri Aug 31 11:03:22 2018 +0200
+++ b/client/src/views/Login.vue	Fri Aug 31 11:12:09 2018 +0200
@@ -163,9 +163,14 @@
           this.loginFailed = false;
           this.$router.push("/");
         })
-        .catch(() => {
+        .catch(error => {
           this.loginFailed = true;
           this.submitted = false;
+          const { status, data } = error.response;
+          displayError({
+            title: "Backend Error",
+            message: `${status}: ${data.message || data}`
+          });
         });
     },
     showPassword() {
@@ -184,7 +189,7 @@
           const { status, data } = error.response;
           displayError({
             title: "Backend Error",
-            message: `${status}: ${data.message}`
+            message: `${status}: ${data.message || data}`
           });
         });
         this.togglePasswordReset();
--- a/client/src/views/Users.vue	Fri Aug 31 11:03:22 2018 +0200
+++ b/client/src/views/Users.vue	Fri Aug 31 11:12:09 2018 +0200
@@ -221,7 +221,7 @@
             const { status, data } = error.response;
             displayError({
               title: "Backend Error",
-              message: `${status}: ${data.message}`
+              message: `${status}: ${data.message || data}`
             });
           });
         })
@@ -229,7 +229,7 @@
           const { status, data } = error.response;
           displayError({
             title: "Backend Error",
-            message: `${status}: ${data.message}`
+            message: `${status}: ${data.message || data}`
           });
         });
     },