Closed dnm13 closed 8 months ago
Hmm... I couldn't find any problems with tests on various node versions. Have you checked your internet connection? (Or perhaps Hitomi's server could have gone down while you writing that code)
which function made a request for https://ltn.hitomi.la/gg.js
?
I'd like to try something with try-catch, can you tell me which one?
Since the data of that page is related to generating the image url, synchronize
method of ImageUrlResolver
instance makes a request.
Additionally, I want you to check if you can access that page manually with your browser or something.
Sorry that I couldn't be of any help, I hope you find out the problem.
.catch
didnt work. The error bleeds to the process.
const getImageUrl = async function getImageUrl(image: hitomiType.Image, extension: "avif" | "webp", options: { isThumbnail?: boolean | undefined; isSmall?: boolean | undefined; }) {
if (!IUR) {
const hitomi: typeof hitomiType = require("node-hitomi").default;
IUR = new hitomi.ImageUrlResolver();
await IUR.synchronize().catch((err: Error) => {
console.log("Error catch from synchronize");
console.log(err.message);
}); // first synchronize
}
return await IUR.getImageUrl(image, extension, options);
}
// ...
CPM.registerJob("hitomi:startup", () => {
setInterval(() => {
if (IUR) IUR.synchronize().catch(
(err: Error) => {
console.log("Error catch from synchronize");
console.log(err.message);
});
}, SynchronizeInterval);
});
console:
HitomiError [REQEUST_REJECTED]: Request to 'https://ltn.hitomi.la/gg.js' was rejected
at ClientRequest.<anonymous> (<omitted>\node_modules\node-hitomi\library\index.js:1:2451)
at ClientRequest.emit (node:events:527:28)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'REQEUST_REJECTED'
}
To be clear, I'm able to access hitomi.la without any problem, and my app was able to fetch some image before the error was thrown.
CPH: Assigning "hitomi:download" job to child process #2
TOKYO NECRO SUICIDE MISSION R downloaded 0
CPH: Assigning "hitomi:download" job to child process #3
TOKYO NECRO SUICIDE MISSION R downloaded 1
CPH: Assigning "hitomi:download" job to child process #4
TOKYO NECRO SUICIDE MISSION R downloaded 2
CPH: Assigning "hitomi:download" job to child process #5
TOKYO NECRO SUICIDE MISSION R downloaded 3
CPH: Assigning "hitomi:download" job to child process #6
I was also able to access https://ltn.hitomi.la/gg.js
on my browser.
I'll try with try-catch
statement for now, hopefully the error doesn't bleed to the process.
Nope, try-catch
didn't work either
const getImageUrl = async function getImageUrl(image: hitomiType.Image, extension: "avif" | "webp", options: { isThumbnail?: boolean | undefined; isSmall?: boolean | undefined; }) {
if (!IUR) {
const hitomi: typeof hitomiType = require("node-hitomi").default;
IUR = new hitomi.ImageUrlResolver();
try {
await IUR.synchronize().catch((err: Error) => {
console.log("Error catch from synchronize");
console.log(err.message);
}); // first synchronize
}
catch (err) {
console.log("Error catch from try-catch synchronize");
console.log(err.message);
}
}
return await IUR.getImageUrl(image, extension, options);
}
CPM.registerJob("hitomi:startup", () => {
setInterval(() => {
if (IUR) {
try {
IUR.synchronize().catch(
(err: Error) => {
console.log("Error catch from synchronize");
console.log(err.message);
});
}
catch (err) {
console.log("Error catch from try-catch synchronize");
console.log(err.message);
}
}
}, SynchronizeInterval);
});
Same error, not going to post it again here to avoid spamming
I believe the most important thing to fix here is the fact that the error can't be catch on both .catch
and try-catch
statement.
Because it somehow immediately broke my loop (the code was run in for
loop, but the .synchronize()
was in interval of every 10 minutes)
I suggest to add .catch()
here:
Code:
IUR.synchronize().catch(err => { console.log("Catched an error from synchronize: ", err); return Promise.reject(err) });
Console:
Catched an error from synchronize: HitomiError [REQEUST_REJECTED]: Request to 'https://ltn.hitomi.la/gg.js' was rejected
at ClientRequest.<anonymous> (<omitted>\node_modules\node-hitomi\library\index.js:2:1747)
at ClientRequest.emit (node:events:527:28)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'REQEUST_REJECTED'
}
CPM: Downloader error on undefined:
Only absolute URLs are supported
Error on downloading 4
HitomiError [REQEUST_REJECTED]: Request to 'https://ltn.hitomi.la/gg.js' was rejected
at ClientRequest.<anonymous> (<omitted>\node_modules\node-hitomi\library\index.js:2:1747)
at ClientRequest.emit (node:events:527:28)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
Retrying...
Notice that after the error was catched, the loop continues and it retries the operation. Although idk why the error was logged twice, but hey it works and doesn't breaks the loop.
Edit: nvm, the error was logged twice because the root caller was also logging the error on Promise reject.
Okay, I made a handler for the promise and will keep investigating what made the request go wrong. I published new release, please check the package's new version.
Okay, the error now can be catched Should I leave this issue open? because although the error can be catched now, it doesn't actually solve the main problem
Since the request problem wasn't solved, I guess it's fine to keep this issue open. Just let me investigate this problem's cause.
Description of bug
Error was thrown, although I quite don't know which function caused this. Using proper catch didn't worked.
Expected behavior
The error can be catch on
.catch
And, should be obvious, but this error should never be thrown, whatever the cause is.Environment
Additional context
Error:
Code (although I'm not sure which function caused this, these are two functions that I've used with):