[bugzilla-gnome-org-extensions] Improve handling of errors
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bugzilla-gnome-org-extensions] Improve handling of errors
- Date: Thu, 20 Nov 2014 22:16:56 +0000 (UTC)
commit 7ccc009bd1fdf0ee327ab2922cd55017536fca39
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Tue Sep 8 21:41:41 2009 -0400
Improve handling of errors
Instead of popping up alerts, display messages in an error div
at the top of the page. Use $.ajax() instead of $.get() for retrieving
the bug and attachment so get a callback on failure.
js/splinter.js | 55 ++++++++++++++++++++++++++++++++++++-----------------
web/index.html | 2 +
web/splinter.css | 7 ++++++
3 files changed, 46 insertions(+), 18 deletions(-)
---
diff --git a/js/splinter.js b/js/splinter.js
index 4de10ca..cee4429 100644
--- a/js/splinter.js
+++ b/js/splinter.js
@@ -12,6 +12,14 @@ var theReview;
const ADD_COMMENT_SUCCESS = /<title>\s*Bug[\S\s]*processed\s*<\/title>/;
const UPDATE_ATTACHMENT_SUCCESS = /<title>\s*Changes\s+Submitted/;
+function displayError(msg) {
+ $("<p></p>")
+ .text(msg)
+ .appendTo("#error");
+ $("#error").show();
+ $("#loading").hide();
+}
+
function updateAttachmentStatus(attachment, newStatus, success, failure) {
var data = {
action: 'update',
@@ -86,23 +94,19 @@ function saveReview() {
alert("Succesfully published the review.");
}
- function error(message) {
- alert(message);
- }
-
addComment(theBug, comment,
function(detail) {
if (newStatus)
updateAttachmentStatus(theAttachment, newStatus,
success,
function() {
- error("Published review; patch status could not be
updated.");
+ displayError("Published review; patch status could not be
updated.");
});
else
success();
},
function(detail) {
- error("Failed to publish review.");
+ displayError("Failed to publish review.");
});
}
@@ -373,16 +377,31 @@ function init() {
return;
}
- $.get("/show_bug.cgi",
- {
- id: bug_id,
- ctype: 'xml',
- excludefield: 'attachmentdata'
- },
- gotBug, "xml");
- $.get("/attachment.cgi",
- {
- id: attachmentId
- },
- gotAttachment, "text");
+ $.ajax({
+ type: 'GET',
+ dataType: 'xml',
+ url: '/show_bug.cgi',
+ data: {
+ id: bug_id,
+ ctype: 'xml',
+ excludefield: 'attachmentdata'
+ },
+ success: gotBug,
+ error: function() {
+ displayError("Failed to retrieve bug");
+ },
+ });
+
+ $.ajax({
+ type: 'GET',
+ dataType: 'text',
+ url: '/attachment.cgi',
+ data: {
+ id: attachmentId
+ },
+ success: gotAttachment,
+ error: function(a, b, c) {
+ displayError("Failed to retrieve attachment");
+ }
+ });
}
diff --git a/web/index.html b/web/index.html
index 4d15957..297da8b 100644
--- a/web/index.html
+++ b/web/index.html
@@ -24,6 +24,8 @@
<span id="attachmentDate"></span>
</div>
</div>
+ <div id="error" style="display: none;">
+ </div>
<div id="controls" style="display: none;">
<div id="oldReviews">
</div>
diff --git a/web/splinter.css b/web/splinter.css
index 3f4502a..b391a33 100644
--- a/web/splinter.css
+++ b/web/splinter.css
@@ -13,6 +13,13 @@ body {
padding: 0.5em;
}
+#error {
+ border: 1px solid black;
+ margin: 0.5em;
+ padding: 0.5em;
+ color: #bb0000;
+}
+
#controls {
padding: 0.5em;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]