Skip to content

Commit ad4425b

Browse files
committed
Laat nu de fout zien, als het ophalen van het rooster, gebruikerstype of
token mislukt, in plaats van stilletjes te falen zoals voorheen
1 parent f246f60 commit ad4425b

4 files changed

Lines changed: 50 additions & 6 deletions

File tree

index.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,34 @@ <h2>Weet je het zeker?</h2>
406406
</section>
407407
</div>
408408
</dialog>
409+
<dialog id="error" role="dialog" aria-label="Fout" closedby="any">
410+
<div>
411+
<svg
412+
xmlns="http://www.w3.org/2000/svg"
413+
viewBox="0 -960 960 960"
414+
id="icon"
415+
>
416+
<path
417+
d="M508.5-291.5Q520-303 520-320t-11.5-28.5Q497-360 480-360t-28.5 11.5Q440-337 440-320t11.5 28.5Q463-280 480-280t28.5-11.5ZM440-440h80v-240h-80v240Zm40 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"
418+
/>
419+
</svg>
420+
<h2>Er is een fout opgetreden</h2>
421+
<section id="content">
422+
<div id="text">
423+
<p></p>
424+
</div>
425+
</section>
426+
<button
427+
class="btn"
428+
id="closeBtn"
429+
commandfor="dialog"
430+
command="close"
431+
style="margin-top: 0"
432+
>
433+
<span data-translate="closeBtn">Sluiten</span>
434+
</button>
435+
</div>
436+
</dialog>
409437
<dialog
410438
id="scanQrCode"
411439
role="dialog"

material.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ p {
488488
font-family: inherit;
489489
font-size: inherit;
490490
float: right;
491+
margin-left: auto;
491492
margin-top: 12px;
492493
view-transition-name: close;
493494
}

schedule.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ async function fetchToken() {
9191
"Content-Type": "application/json",
9292
},
9393
});
94+
const data = await response.json();
9495
if (!response.ok) {
95-
throw new Error(`Error ${response.status}: ${response.statusText}`);
96+
errorMessage(data.response.message);
9697
}
97-
const data = await response.json();
9898
localStorage.setItem("access_token", data.access_token);
9999
accessToken = localStorage.getItem("access_token");
100100
} catch (error) {
@@ -140,6 +140,7 @@ async function userInfo() {
140140
userType1 = "teacher";
141141
} else if (!data.response.data[0]) {
142142
console.error(data);
143+
errorMessage(data.response.message);
143144
} else {
144145
schoolInSchoolYears(data.response.data[0].schoolInSchoolYears);
145146
}
@@ -366,7 +367,10 @@ function show(id, title, hideBack) {
366367
}
367368
});
368369
}
369-
370+
function errorMessage(e) {
371+
document.querySelector("#error p").innerText = e;
372+
document.getElementById("error").showModal();
373+
}
370374
function renderAnnouncements() {
371375
const content = document.getElementById("allAnnouncements");
372376
content.innerHTML = "";
@@ -501,6 +505,9 @@ async function fetchSchedule(year, week, isFirstLoad) {
501505
}
502506
);
503507
const data = await response.json();
508+
if (!response.ok) {
509+
errorMessage(data.response.message);
510+
}
504511
const appointments = data.response.data[0].appointments;
505512
const isHoliday = !appointments[0];
506513
const schedule = document.getElementById("schedule");

style.css

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,13 @@ table {
317317
#clearSettings #content {
318318
width: 282px;
319319
}
320+
#error,
321+
#error #content {
322+
width: 310px;
323+
}
320324
#clearSettings div,
321-
#scanQrCode div {
325+
#scanQrCode div,
326+
#error div {
322327
display: flex;
323328
flex-direction: column;
324329
gap: 1rem;
@@ -331,7 +336,9 @@ table {
331336
letter-spacing: 0.1px;
332337
}
333338
#clearSettings h2,
334-
#clearSettings #content {
339+
#clearSettings #content,
340+
#error h2,
341+
#error #content {
335342
margin: 0;
336343
padding: 0;
337344
}
@@ -346,7 +353,8 @@ table {
346353
align-items: center;
347354
}
348355
#clearSettings #icon,
349-
#scanQrCode #icon {
356+
#scanQrCode #icon,
357+
#error #icon {
350358
fill: var(--accent-text);
351359
width: 2rem;
352360
height: 2rem;

0 commit comments

Comments
 (0)