Commit fa9cc706 authored by Tomáš Peterka's avatar Tomáš Peterka

[erp5_web_renderjs_ui] Rearrange form-error-handling code so an additional...

[erp5_web_renderjs_ui] Rearrange form-error-handling code so an additional fail() function is not necessary
parent 9ba4dab0
...@@ -121,6 +121,7 @@ ...@@ -121,6 +121,7 @@
.push(function (validity) { .push(function (validity) {
if (validity) { if (validity) {
return erp5_form.getContent() return erp5_form.getContent()
// try to send the form data over the network to jIO storage
.push(function (data) { .push(function (data) {
data[form_id.key] = form_id['default']; data[form_id.key] = form_id['default'];
...@@ -134,6 +135,7 @@ ...@@ -134,6 +135,7 @@
) )
]); ]);
}) })
// handle response from the server
.push(function (result_list) { .push(function (result_list) {
if (result_list[1].target.responseType === "blob") { if (result_list[1].target.responseType === "blob") {
return jIO.util.readBlobAsText(result_list[1].target.response); return jIO.util.readBlobAsText(result_list[1].target.response);
...@@ -153,26 +155,32 @@ ...@@ -153,26 +155,32 @@
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
if (error.target !== undefined) { if (error.target !== undefined) {
var error_text; var error_text,
promise;
if (error.target.status === 400) { if (error.target.status === 400) {
error_text = 'Input data has errors'; error_text = 'Input data has errors';
} else if (error.target.status === 403) { } else if (error.target.status === 403) {
error_text = 'You do not have the permissions to edit the object'; error_text = 'You do not have the permissions to edit the object';
} else if (error.target.status === 0 && error.total === 0) { } else if (error.target.status === 0) {
// backend cannot be reached and no data is being transfered // no/default=0 status means a network connection problem
error_text = 'Document was not saved! Resubmit when you are online or the document accessible'; error_text = 'Document was not saved! Resubmit when you are online or the document accessible';
} else { } else {
// display "unknown error" rather than destroying user's form data (throwing an error) // display "unknown error" rather than destroying user's form data (throwing an error)
error_text = 'Encountered an unknown error. Try to resubmit'; error_text = 'Encountered an unknown error. Try to resubmit';
} }
if (error_text !== undefined) { if (error_text !== undefined) {
return form_gadget.notifySubmitted() promise = form_gadget.notifySubmitted()
.push(function () { .push(function () {
return form_gadget.translate(error_text); return form_gadget.translate(error_text);
}) })
.push(function (message) { .push(function (message) {
return form_gadget.notifyChange(message + '.'); return form_gadget.notifyChange(message + '.');
}) });
}
if (error.target.status === 400) {
// server validation of form data failed (indicated by reponse code 400)
// we parse out field errors and display them to the user
promise
.push(function () { .push(function () {
// when the server-side validation returns the error description // when the server-side validation returns the error description
if (error.target.responseType === "blob") { if (error.target.responseType === "blob") {
...@@ -183,10 +191,9 @@ ...@@ -183,10 +191,9 @@
}) })
.push(function (event) { .push(function (event) {
return form_gadget.displayFormulatorValidationError(JSON.parse(event.target.result)); return form_gadget.displayFormulatorValidationError(JSON.parse(event.target.result));
}) });
// most likely a JSON parse error because of invalid response which we will quietly ignore
.fail(function () {});
} }
return promise;
} }
// throwing an error is the last desperate option // throwing an error is the last desperate option
throw error; throw error;
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>960.31544.14430.63812</string> </value> <value> <string>960.32649.42585.31078</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1499089561.38</float> <float>1499158937.47</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment