Commit ec4b1276 authored by Roque's avatar Roque

erp5_officejs: better error catching in local controller gadget

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