Add hint popup on string length overflow

a8bb8a6703d5528890abeaa971880f6447fbc482

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +9 -2Showing whitespace changes
public/script.js+7 -1
@@ -1205,7 +1205,7 @@ export async function getCharacters() {
12051205 headers: getRequestHeaders(),
12061206 body: JSON.stringify({}),
12071207 });
12081208 if (response.ok === true) {
12091209 const previousAvatar = this_chid !== undefined ? characters[this_chid]?.avatar : null;
12101210 characters.splice(0, characters.length);
12111211 const getData = await response.json();
@@ -1234,6 +1234,12 @@ export async function getCharacters() {
12341234
12351235 await getGroups();
12361236 await printCharacters(true);
1237+ } else {
1238+ console.error('Failed to fetch characters:', response.statusText);
1239+ const errorData = await response.json();
1240+ if (errorData?.overflow) {
1241+ await Popup.show.text(t`Character data length limit reached`, t`To resolve this, set "performance.lazyLoadCharacters" to "true" in config.yaml and restart the server.`);
1242+ }
12371243 }
12381244}
12391245
src/endpoints/characters.js+2 -1
@@ -1213,7 +1213,8 @@ router.post('/all', async function (request, response) {
12131213 return response.send(data);
12141214 } catch (err) {
12151215 console.error(err);
1216- response.sendStatus(500);
1216+ const isRangeError = err instanceof RangeError;
1217+ response.status(500).send({ overflow: isRangeError, error: true });
12171218 }
12181219});
12191220