Improve error management
authorymh <ymh.work@gmail.com>
Wed, 28 Nov 2018 18:25:11 +0100
changeset 181 cda96c025330
parent 180 62bffc051e1c
child 182 2dbb6ddbf645
Improve error management
client/src/components/Login.js
--- a/client/src/components/Login.js	Wed Nov 28 15:45:37 2018 +0100
+++ b/client/src/components/Login.js	Wed Nov 28 18:25:11 2018 +0100
@@ -62,8 +62,12 @@
       )
     }
 
-    const errors = R.path(['data','non_field_errors'], errorMessages);
-    if (errors) {
+    const errors = R.reduce(
+      (acc, p) => R.concat(acc, R.ifElse(Array.isArray, R.identity, v => [v,])(R.pathOr([], ['data', p], errorMessages))),
+      [],
+      ['non_field_errors', 'detail']
+    );
+    if (errors && errors.length > 0 ) {
       return (
         <div className="alert alert-danger mt-4" role="alert">
         { errors.map((message, key) =>