1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-05 12:56:22 -07:00

Properly catch errors in thread API AJAX requests

This commit is contained in:
Eggbertx 2022-08-17 14:30:57 -07:00
parent 692befd8c3
commit 245ba730eb
4 changed files with 20 additions and 16 deletions

View file

@ -0,0 +1,17 @@
/* global webroot */
import $ from "jquery";
export function getThreadJSON(threadID, board) {
return $.ajax({
url: `${webroot}${board}/res/${threadID}.json`,
cache: false,
dataType: "json",
error: function(e, status, statusText) {
// clearInterval(threadWatcherInterval);
return {};
}
}).catch(e => {
return {};
});
}

View file

@ -12,6 +12,7 @@ import { getBooleanStorageVal, getNumberStorageVal } from "./storage";
import { currentThread, getPageThread, insideOP } from "./postinfo"; import { currentThread, getPageThread, insideOP } from "./postinfo";
import { addPostDropdown } from "./dom/postdropdown"; import { addPostDropdown } from "./dom/postdropdown";
import { createPostElement } from "./dom/postelement"; import { createPostElement } from "./dom/postelement";
import { getThreadJSON } from "./api/threads"
import { openQR } from "./dom/qr"; import { openQR } from "./dom/qr";
let doClickPreview = false; let doClickPreview = false;
@ -28,8 +29,6 @@ let currentThreadJSON = {
posts: [] posts: []
}; };
export function getUploadPostID(upload, container) { export function getUploadPostID(upload, container) {
// if container, upload is div.upload-container // if container, upload is div.upload-container
// otherwise it's img or video // otherwise it's img or video
@ -44,9 +43,6 @@ export function updateThreadJSON() {
if(!(json.posts instanceof Array) || json.posts.length === 0) if(!(json.posts instanceof Array) || json.posts.length === 0)
return; return;
currentThreadJSON = json; currentThreadJSON = json;
}).catch(e => {
console.error(`Failed updating current thread: ${e}`);
clearInterval(threadWatcherInterval);
}); });
} }
@ -244,15 +240,6 @@ export function quote(no) {
} }
window.quote = quote; window.quote = quote;
export function getThreadJSON(threadID, board) {
return $.ajax({
url: `${webroot}${board}/res/${threadID}.json`,
cache: false,
dataType: "json"
});
}
$(() => { $(() => {
let pageThread = getPageThread(); let pageThread = getPageThread();
if(pageThread.op >= 1) { if(pageThread.op >= 1) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long