Commit ec4b1276 authored by Roque's avatar Roque

erp5_officejs: better error catching in local controller gadget

parent 5400a394
...@@ -191,7 +191,8 @@ ...@@ -191,7 +191,8 @@
form_definition, form_definition,
query_type, query_type,
query_parent, query_parent,
query_reference; query_reference,
error;
query_reference = new SimpleQuery({ query_reference = new SimpleQuery({
key: "reference", key: "reference",
operator: "", operator: "",
...@@ -218,7 +219,9 @@ ...@@ -218,7 +219,9 @@
return gadget.jio_allDocs({query: query}) return gadget.jio_allDocs({query: query})
.push(function (data) { .push(function (data) {
if (data.data.rows.length === 0) { if (data.data.rows.length === 0) {
throw "Can not find action '" + action_reference + "' for portal type '" + portal_type + "'"; error = new Error("Can not find action '" + action_reference + "' for portal type '" + portal_type + "'");
error.status_code = 400;
throw error;
} }
return gadget.jio_get(data.data.rows[0].id); return gadget.jio_get(data.data.rows[0].id);
}) })
......
...@@ -53,9 +53,12 @@ ...@@ -53,9 +53,12 @@
if (jio_document.portal_type === undefined) { if (jio_document.portal_type === undefined) {
throw new Error('Can not display document: ' + options.jio_key); throw new Error('Can not display document: ' + options.jio_key);
} }
}, function () {}) }, function (error) {
.push(function () { // instaceof error is Object, so use status_code and undefined jio_key
return gadget.getSetting('parent_portal_type'); if (error.status_code === 400 && !options.jio_key) {
return gadget.getSetting('parent_portal_type');
}
throw error;
}) })
.push(function (parent_portal_type) { .push(function (parent_portal_type) {
if (jio_document) { if (jio_document) {
...@@ -70,8 +73,11 @@ ...@@ -70,8 +73,11 @@
}) })
.push(function (result) { .push(function (result) {
return result; return result;
}, function () { }, function (error) {
return gadget_utils.getFormDefinition(portal_type, default_view); if (error.status_code === 400) {
return gadget_utils.getFormDefinition(portal_type, default_view);
}
throw error;
}) })
.push(function (result) { .push(function (result) {
form_definition = result; form_definition = result;
......
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