Coder Social home page Coder Social logo

Comments (10)

H2Owater425 avatar H2Owater425 commented on June 14, 2024 1

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.

from node-hitomi.

H2Owater425 avatar H2Owater425 commented on June 14, 2024 1

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.

from node-hitomi.

H2Owater425 avatar H2Owater425 commented on June 14, 2024

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)

from node-hitomi.

dnm13 avatar dnm13 commented on June 14, 2024

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?

from node-hitomi.

H2Owater425 avatar H2Owater425 commented on June 14, 2024

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.

from node-hitomi.

dnm13 avatar dnm13 commented on June 14, 2024

.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.

from node-hitomi.

dnm13 avatar dnm13 commented on June 14, 2024

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

from node-hitomi.

dnm13 avatar dnm13 commented on June 14, 2024

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)

from node-hitomi.

dnm13 avatar dnm13 commented on June 14, 2024

I suggest to add .catch() here:
image

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.

from node-hitomi.

dnm13 avatar dnm13 commented on June 14, 2024

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

from node-hitomi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.