Add better error handling
This commit is contained in:
parent
2bf9a90901
commit
56cd21859a
@ -31,7 +31,7 @@
|
||||
<td colspan="5">
|
||||
<div class="work-area">
|
||||
|
||||
<div class="window">
|
||||
<div class="window" style="z-index: 90; left: 17px; top: 41px;">
|
||||
<div class="window-title">Форма ввода</div>
|
||||
<div class="window-body">
|
||||
<form class="form" id="form">
|
||||
@ -68,7 +68,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="window">
|
||||
<div class="window" style="z-index: 93; left: 89px; top: 416px;">
|
||||
<div class="window-title">Ответ</div>
|
||||
<div class="window-body">
|
||||
<table class="table">
|
||||
@ -87,7 +87,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="window three-d">
|
||||
<div class="window three-d" style="z-index: 91; left: 559px; top: 66px;">
|
||||
<div class="window-title">areas.png</div>
|
||||
<div class="window-body">
|
||||
<img src="images/areas.png" alt="Мишень">
|
||||
|
||||
49
script.ts
49
script.ts
@ -79,14 +79,14 @@ rButtons.forEach((button: HTMLButtonElement) => {
|
||||
});
|
||||
});
|
||||
|
||||
const form = document.querySelector('#form');
|
||||
form.addEventListener('submit', e => {
|
||||
e.preventDefault();
|
||||
if (isNaN(request.y)) {
|
||||
document.querySelector<HTMLAudioElement>('#error_sound').play();
|
||||
const _window = document.createElement('div');
|
||||
_window.classList.add('window');
|
||||
_window.innerHTML = `
|
||||
const showError = (errorText: string) => {
|
||||
document.querySelector<HTMLAudioElement>('#error_sound').play();
|
||||
const _window = document.createElement('div');
|
||||
_window.classList.add('window');
|
||||
_window.style.zIndex = String(500);
|
||||
_window.style.left = "35%";
|
||||
_window.style.top = "35%";
|
||||
_window.innerHTML = `
|
||||
<div class="window-title">
|
||||
<span>Ошибка</span>
|
||||
<span class="button close">X</span>
|
||||
@ -94,11 +94,18 @@ form.addEventListener('submit', e => {
|
||||
<div class="window-body">
|
||||
<div class="error">
|
||||
<img src="images/error.png" alt="Error Icon"/>
|
||||
<p>Ошибка, проверьте, что Y это число</p>
|
||||
<p>${errorText}</p>
|
||||
</div>
|
||||
</div>`;
|
||||
windowDragHandler(_window);
|
||||
document.querySelector<HTMLDivElement>('.work-area').append(_window);
|
||||
windowDragHandler(_window);
|
||||
document.querySelector<HTMLDivElement>('.work-area').append(_window);
|
||||
}
|
||||
|
||||
const form = document.querySelector('#form');
|
||||
form.addEventListener('submit', e => {
|
||||
e.preventDefault();
|
||||
if (isNaN(request.y)) {
|
||||
showError('Ошибка, проверьте, что Y это число')
|
||||
return;
|
||||
}
|
||||
|
||||
@ -108,12 +115,18 @@ form.addEventListener('submit', e => {
|
||||
r: String(request.r),
|
||||
});
|
||||
const response = fetch(`/ipa/cgi.jar?${params.toString()}`);
|
||||
response.then(response => response.text().then(
|
||||
html => {
|
||||
const element = document.createElement('tr');
|
||||
element.innerHTML += html;
|
||||
if (response.headers.get('X-Gol') === 'no') element.classList.add('grey');
|
||||
document.querySelector("#results").append(element);
|
||||
response.then(response => {
|
||||
if (response.status !== 200) {
|
||||
showError("Ошибка при обработке запроса. Пожалуйста, попробуйте позже");
|
||||
return;
|
||||
}
|
||||
));
|
||||
response.text().then(
|
||||
html => {
|
||||
const element = document.createElement('tr');
|
||||
element.innerHTML += html;
|
||||
if (response.headers.get('X-Gol') === 'no') element.classList.add('grey');
|
||||
document.querySelector("#results").append(element);
|
||||
}
|
||||
)
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user