Commit 92beebd3 authored by Jérome Perrin's avatar Jérome Perrin

web_renderjs_ui: make error page a bit more readable

- indent the json representation of error
- if error is an XMLHttpRequest:
  - include the server side error response in an iframe
  - split response headers

/reviewed-on nexedi/erp5!981
parent 70d38eee
...@@ -120,9 +120,9 @@ ...@@ -120,9 +120,9 @@
var error_list = [original_error], var error_list = [original_error],
i, i,
error, error,
error_response,
error_text = ""; error_text = "";
// Do not break the application in case of errors. // Do not break the application in case of errors.
// Display it to the user for now, // Display it to the user for now,
// and allow user to go back to the frontpage // and allow user to go back to the frontpage
...@@ -144,6 +144,9 @@ ...@@ -144,6 +144,9 @@
} }
} }
if (error instanceof XMLHttpRequest) { if (error instanceof XMLHttpRequest) {
if (error.getResponseHeader('Content-Type').indexOf('text/') === 0) {
error_response = error.response;
}
error = { error = {
message: error.toString(), message: error.toString(),
readyState: error.readyState, readyState: error.readyState,
...@@ -151,14 +154,16 @@ ...@@ -151,14 +154,16 @@
statusText: error.statusText, statusText: error.statusText,
response: error.response, response: error.response,
responseUrl: error.responseUrl, responseUrl: error.responseUrl,
response_headers: error.getAllResponseHeaders() response_headers: (error.getAllResponseHeaders()
? error.getAllResponseHeaders().split('\r\n')
: null)
}; };
} }
if (error.constructor === Array || if (error.constructor === Array ||
error.constructor === String || error.constructor === String ||
error.constructor === Object) { error.constructor === Object) {
try { try {
error = JSON.stringify(error); error = JSON.stringify(error, null, ' ');
} catch (ignore) { } catch (ignore) {
} }
} }
...@@ -185,9 +190,20 @@ ...@@ -185,9 +190,20 @@
// Gadget has not yet been correctly initialized // Gadget has not yet been correctly initialized
throw error; throw error;
} }
if (error_response && error_response.text) {
return error_response.text().then(
function (request_error_text) {
return gadget.changeState({
error_text: error_text,
request_error_text: request_error_text,
url: undefined
});
}
);
}
return gadget.changeState({ return gadget.changeState({
error_text: error_text, error_text: error_text,
request_error_text: error_response,
url: undefined url: undefined
}); });
...@@ -683,6 +699,7 @@ ...@@ -683,6 +699,7 @@
var element = gadget.props.content_element, var element = gadget.props.content_element,
container = document.createElement("section"), container = document.createElement("section"),
paragraph, paragraph,
iframe,
link; link;
paragraph = document.createElement("p"); paragraph = document.createElement("p");
...@@ -731,6 +748,13 @@ ...@@ -731,6 +748,13 @@
} }
element.appendChild(container); element.appendChild(container);
// make an iframe to display error page from XMLHttpRequest.
if (gadget.state.request_error_text) {
iframe = document.createElement('iframe');
container.appendChild(iframe);
iframe.srcdoc = gadget.state.request_error_text;
}
// reset gadget state // reset gadget state
gadget.state = JSON.parse(default_state_json_string); gadget.state = JSON.parse(default_state_json_string);
}); });
......
...@@ -313,7 +313,7 @@ ...@@ -313,7 +313,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1469697401.26</float> <float>1469697401.27</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
<tr> <tr>
<td>assertTextPresent</td> <td>assertTextPresent</td>
<td>"status":404</td> <td>"status": 404</td>
<td></td> <td></td>
</tr> </tr>
...@@ -60,6 +60,35 @@ ...@@ -60,6 +60,35 @@
<td></td> <td></td>
</tr> </tr>
<!-- when an action failed server side, the server side error is displayed in an ifame of the error page -->
<tr>
<td>waitForElementPresent</td>
<td>//div[@role="main"]//iframe</td>
<td></td>
</tr>
<tr>
<td>selectFrame</td>
<td>//div[@role="main"]//iframe</td>
<td></td>
</tr>
<tr>
<td>waitForTextPresent</td>
<td>Not Found</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>gadget_erp5_page_foobar.html was not found on this server.</td>
<td></td>
</tr>
<tr>
<td>selectFrame</td>
<td>relative=top</td>
<td></td>
</tr>
<tr> <tr>
<td>assertTextPresent</td> <td>assertTextPresent</td>
<td>#/?page=foobar</td> <td>#/?page=foobar</td>
......
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