Skip to content

Commit

Permalink
fix load function: alert if request failed
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaAmega committed Jan 6, 2022
1 parent 7b0aa12 commit d853b0c
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions utils/tests-visualizer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,25 @@ <h1 id="loading" style="position: absolute; margin-left: 1em;">Loading (10 secon
FORMAT TSV`;

function load(query, callback) {
const xhr = new XMLHttpRequest;
xhr.open('POST', "https://play-ci.clickhouse.com/?user=play&add_http_cors_header=1", true);

xhr.onreadystatechange = function()
{
if (this.readyState === XMLHttpRequest.DONE && this.status == 200) {
callback(this.response);
}
}

xhr.send(query);
fetch(
"https://play-ci.clickhouse.com?user=play&add_http_cors_header=1",
{ method: "POST", body: query }
)
.then((response) => {
if (!response.ok) throw new Error(`Data download failed\nHTTP status ${response.status}`);
return response.json();
})
.then((json) => callback(json))
.catch(alert);
}

load(query, renderResponse);

let data;
let canvas = document.getElementById('canvas');

function renderResponse(response) {
data = JSON.parse(response);
function renderResponse(response_json) {
data = response_json;

const last_pixel = data[data.length - 1];
canvas.width = last_pixel[0] + 1;
Expand Down Expand Up @@ -100,9 +99,9 @@ <h1 id="loading" style="position: absolute; margin-left: 1em;">Loading (10 secon

load(test_names_query, saveTestNames);

function saveTestNames(response)
function saveTestNames(response_json)
{
test_names = JSON.parse(response).data;
test_names = response_json.data;
}

canvas.addEventListener('mousemove', event => {
Expand Down

0 comments on commit d853b0c

Please sign in to comment.