Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}).then((resp) => {
if (resp.ok) {
// Triaging was successful.
this.status = newStatus;
this.triageHistory.unshift({
user: 'me',
ts: Date.now().toString(),
});
this._render();
sendEndTask(this);
} else {
// Triaging did not work (possibly because the user was not logged in). We want to set
// the status of the triage-sk back to what it was to give a visual indication it did not
// go through. Additionally, toast error message should catch the user's attention.
console.error(resp);
errorMessage(
`Unexpected error triaging: ${resp.status} ${resp.statusText} ` +
'(Are you logged in with the right account?)', 8000);
this.querySelector('triage-sk')!.value = this.status;
this._render();
sendEndTask(this);
}
}).catch((e) => {
sendFetchError(this, e, 'triaging')
});
const results = (await jsonOrThrow(request)) as RunResults;
// The .text field returned is empty, so repopulate it with the value we
// stored in body.
results.text = body.code;
this.runResults = results;
this._render();
this.dispatchEvent(
new CustomEvent('fiddle-success', {
detail: this._runResults.fiddleHash,
bubbles: true,
}),
);
} catch (error) {
errorMessage(error);
} finally {
this.spinner!.active = false;
}
}
}).catch((msg) => {
this._alertSpinner.active = false;
errorMessage(msg);
});
}
this._state.filename = toLoad.name;
this._width = DEFAULT_SIZE;
this._height = DEFAULT_SIZE;
this._render();
});
reader.addEventListener('error', () => {
errorMessage('Failed to load '+ toLoad.name);
});
reader.readAsDataURL(toLoad);
} else {
let msg = `Bad file type ${toLoad.name}, only .json and .zip supported`;
if (!allowZips) {
msg = `Bad file type ${toLoad.name}, only .json supported`;
}
errorMessage(msg);
this._state.filename = '';
this._state.lottie = '';
}
}
_validateTask(): void {
if (!$('patch-sk', this).every((patch) => (patch as PatchSk).validate())) {
return;
}
if (!($$('#metric_name', this) as InputSk).value) {
errorMessage('Please specify a metric name');
($$('#metric_name', this) as InputSk).focus();
return;
}
if (!($$('#analysis_task_id', this) as InputSk).value && !($$('#custom_traces', this) as InputSk).value) {
errorMessage('Please specify an analysis task id or custom traces');
($$('#analysis_task_id', this) as InputSk).focus();
return;
}
if (!($$('#description', this) as InputSk).value) {
errorMessage('Please specify a description');
($$('#description', this) as InputSk).focus();
return;
}
if (this._moreThanThreeActiveTasks()) {
return;
}
_add(replace) {
this._queryDialog.close();
const q = this._query.current_query;
if (!q || q.trim() === '') {
errorMessage('The query must not be empty.');
return;
}
this.state = Object.assign({}, this.state, this._range.state);
if (replace) {
this._removeAll(true);
}
if (this.state.queries.indexOf(q) === -1) {
this.state.queries.push(q);
}
const body = this._requestFrameBodyFullFromState();
this._requestFrame(body, (json) => {
this._addTraces(json, true);
});
}
_catch(msg) {
this._requestId = '';
if (msg) {
errorMessage(msg, 10000);
}
this._percent.textContent = '';
this.spinning = false;
}
}).then(jsonOrThrow).then(json => {
errorMessage(e.detail.name + ": " + json.result);
this._loadData();
}).catch(errorMessage);
}
private async doImpl(url: string, detail: any, action: (json: any)=> void): Promise {
try {
const resp = await fetch(url, {
body: JSON.stringify(detail),
headers: {
'content-type': 'application/json',
},
credentials: 'include',
method: 'POST',
});
const json = await jsonOrThrow(resp);
action(json);
} catch (msg) {
errorMessage(msg);
}
}