Skip to content

Commit

Permalink
Show error message when API calls fail (sosedoff#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
sosedoff authored and Jonas Falck committed Apr 10, 2024
1 parent a195847 commit bda2140
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
13 changes: 13 additions & 0 deletions static/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,19 @@
box-shadow: #eee 0 0 5px;
}

#error_banner {
line-height: 30px;
text-align: center;
background-color: #be2740;
color: #fff;
display: none;
position: fixed;
bottom: 0px;
left: 0px;
right: 0px;
height: 30px;
}

/* -------------------------------------------------------------------------- */

#custom_query {
Expand Down
1 change: 1 addition & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,6 @@ <h3 class="text-center">SSH Connection</h3>
<li><a href="#" data-action="filter_by_value">Filter Rows By Value</a></li>
</ul>
</div>
<div id="error_banner"></div>
</body>
</html>
22 changes: 20 additions & 2 deletions static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ function apiCall(method, path, params, cb) {
},
success: cb,
error: function(xhr, status, data) {
if (status == "timeout") {
return cb({ error: "Query timeout after " + timeout + "s" });
switch(status) {
case "error":
if (xhr.readyState == 0) { // 0 = UNSENT
showErrorBanner("Sorry, something went wrong with your request. Refresh the page and try again!");
}
break;
case "timeout":
return cb({ error: "Query timeout after " + timeout + "s" });
}

cb(jQuery.parseJSON(xhr.responseText));
Expand Down Expand Up @@ -105,6 +111,18 @@ function encodeQuery(query) {
return Base64.encode(query).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ".");
}

function showErrorBanner(text) {
if (window.errBannerTimeout != null) {
clearTimeout(window.errBannerTimeout);
}

window.errBannerTimeout = setTimeout(function() {
$("#error_banner").fadeOut("fast").text("");
}, 3000);

$("#error_banner").text(text).show();
}

function buildSchemaSection(name, objects) {
var section = "";

Expand Down

0 comments on commit bda2140

Please sign in to comment.