Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 166a1a4

Browse files
committed
Better use of response detail from new server
1 parent 7a99f90 commit 166a1a4

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

runestone/common/js/bookfuncs.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ function addReadingList() {
9999
name: "link",
100100
class: "btn btn-lg ' + 'buttonConfirmCompletion'",
101101
href: nxt_link,
102-
text: `Continue to page ${position + 2
103-
} of ${num_readings} in the reading assignment.`,
102+
text: `Continue to page ${
103+
position + 2
104+
} of ${num_readings} in the reading assignment.`,
104105
});
105106
} else {
106107
l = $("<div />", {
107-
text:
108-
"This page is not part of the last reading assignment you visited.",
108+
text: "This page is not part of the last reading assignment you visited.",
109109
});
110110
}
111111
$("#main-content").append(l);
@@ -195,7 +195,7 @@ class PageProgressBar {
195195
if (
196196
val == 100.0 &&
197197
$("#completionButton").text().toLowerCase() ===
198-
"mark as completed"
198+
"mark as completed"
199199
) {
200200
$("#completionButton").click();
201201
}
@@ -211,23 +211,20 @@ async function handlePageSetup() {
211211
"Content-type": "application/json; charset=utf-8",
212212
Accept: "application/json",
213213
});
214-
let data = { timezoneoffset: new Date().getTimezoneOffset() / 60 }
215-
let request = new Request(
216-
"/logger/set_tz_offset",
217-
{
218-
method: "POST",
219-
body: JSON.stringify(data),
220-
headers: headers,
221-
}
222-
);
214+
let data = { timezoneoffset: new Date().getTimezoneOffset() / 60 };
215+
let request = new Request("/logger/set_tz_offset", {
216+
method: "POST",
217+
body: JSON.stringify(data),
218+
headers: headers,
219+
});
223220
try {
224221
let response = await fetch(request);
225-
if (response.status != 200) {
226-
console.log(`Failed to set timezone! ${response.statusText}`)
222+
if (!response.ok) {
223+
console.error(`Failed to set timezone! ${response.statusText}`);
227224
}
228225
data = await response.json();
229226
} catch (e) {
230-
227+
console.error(`Error setting timezone ${e}`);
231228
}
232229

233230
if (eBookConfig.isLoggedIn) {

runestone/common/js/runestonebase.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,12 @@ export default class RunestoneBase {
9999
try {
100100
let response = await fetch(request);
101101
if (!response.ok) {
102-
throw new Error("Failed to save the log entry");
102+
let detail = await response.json();
103+
console.error(detail);
104+
throw new Error(`Failed to save the log entry ${detail}`);
105+
} else {
106+
post_return = response.json();
103107
}
104-
post_return = response.json();
105108
} catch (e) {
106109
if (this.isTimed) {
107110
alert(
@@ -260,7 +263,7 @@ export default class RunestoneBase {
260263
*/
261264
repopulateFromStorage(data) {
262265
// decide whether to use the server's answer (if there is one) or to load from storage
263-
if (data !== null && this.shouldUseServer(data)) {
266+
if (data !== null && data !== "no data" && this.shouldUseServer(data)) {
264267
this.restoreAnswers(data);
265268
this.setLocalStorage(data);
266269
} else {

0 commit comments

Comments
 (0)