Commit 01565a5c authored by Roque's avatar Roque

erp5_officejs: more debug info in bootloader error display

parent 2def06cb
......@@ -3,6 +3,91 @@
(function (window, rJS) {
"use strict";
function displayErrorContent(gadget, original_error) {
var error_list = [original_error],
i,
error,
error_text = "";
// Do not break the application in case of errors.
// Display it to the user for now,
// and allow user to go back to the frontpage
// Add error handling stack
error_list.push(new Error('stopping ERP5JS'));
for (i = 0; i < error_list.length; i += 1) {
error = error_list[i];
if (error instanceof Event) {
error = {
string: error.toString(),
message: error.message,
type: error.type,
target: error.target
};
if (error.target !== undefined) {
error_list.splice(i + 1, 0, error.target);
}
}
if (error instanceof XMLHttpRequest) {
error = {
message: error.toString(),
readyState: error.readyState,
status: error.status,
statusText: error.statusText,
response: error.response,
responseUrl: error.responseUrl,
response_headers: error.getAllResponseHeaders()
};
}
if (error.constructor === Array ||
error.constructor === String ||
error.constructor === Object) {
try {
error = JSON.stringify(error);
} catch (ignore) {
}
}
error_text += error.message || error;
error_text += '\n';
if (error.fileName !== undefined) {
error_text += 'File: ' +
error.fileName +
': ' + error.lineNumber + '\n';
}
if (error.stack !== undefined) {
error_text += 'Stack: ' + error.stack + '\n';
}
error_text += '---\n';
}
console.error(original_error);
if (original_error instanceof Error) {
console.error(original_error.stack);
}
console.log("generated error_text:");
console.log(error_text);
return error_text;
/*if (gadget.props === undefined) {
// Gadget has not yet been correctly initialized
throw error;
}
return gadget.changeState({
error_text: error_text,
url: undefined
});*/
}
function displayError(gadget, error) {
if (error instanceof RSVP.CancellationError) {
return "RSVP cancelation error";
}
return displayErrorContent(gadget, error);
}
rJS(window)
.declareMethod('render', function (options) {
return this.changeState(options);
......@@ -23,6 +108,10 @@
if (modification_dict.error) {
error_div = gadget.element.querySelector(".error-message");
message = "Last Error: ";
console.log("CALLING DISPLAY ERROR...");
var error_text = displayError(gadget, gadget.state.error);
if (gadget.state.error.message) {
message += gadget.state.error.message;
} else {
......@@ -34,6 +123,7 @@
} else {
message += " " + modification_dict.error;
}
message += " - ERROR TEXT: " + error_text;
error_div.textContent = message;
}
if (modification_dict.redirect_url) {
......
"""
================================================================================
Proxy of StaticWebSection_getDocumentValue to allow redirection
================================================================================
"""
# parameters
# ------------------------------------------------------------------------------
# name main_template
# this script will be cloned into a new one. If the request arrives here, it's because it's using the static web section for hateoas URLs
# so name should be the relative_url (e.g. portal_types/Web%20Page/jio_view)
# that relative_url should be use to call ERP5Document_getHateoas script
# with query: ?mode=traverse&relative_url=portal_types%2FWeb%20Page%2Fjio_view&view=definition_view
# catch KeyError on source_path with urls "", "?", "/?", "...&"
try:
context.REQUEST.other['source_path'] = name
except KeyError:
return context
return context
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>name, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>StaticWebSection_getDocumentValue</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
"""
================================================================================
Redirect to domain specified as layout property on website
================================================================================
"""
# parameters
# ------------------------------------------------------------------------------
INDEX = "index.html"
REQUEST = context.REQUEST
query_string = REQUEST["QUERY_STRING"]
redirect_domain = context.getLayoutProperty("redirect_domain")
redirect_url = redirect_domain
status_code = 301
if context.getLayoutProperty("use_moved_temporarily"):
status_code = 302
try:
source_path = REQUEST.other["source_path"]
redirect_url = "/".join([redirect_url, source_path])
except(KeyError):
redirect_url = redirect_url + "/"
if query_string:
redirect_url = '?'.join([redirect_url, query_string])
if redirect_url.find(INDEX) > -1 and not redirect_url.endswith(INDEX):
redirect_url = redirect_url.replace(INDEX, '')
if redirect_url.find(INDEX) > -1 and REQUEST['ACTUAL_URL'].find(INDEX) == -1:
redirect_url = redirect_url.replace(INDEX, '')
return context.Base_redirect(redirect_url, status_code=status_code)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>StaticWebSection_getRedirectSourceUrl</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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