Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getActiveEvents("de") - Error: Too Many Redirects #2

Closed
Roo7K1d opened this issue Feb 23, 2024 · 1 comment
Closed

getActiveEvents("de") - Error: Too Many Redirects #2

Roo7K1d opened this issue Feb 23, 2024 · 1 comment
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Roo7K1d
Copy link
Owner

Roo7K1d commented Feb 23, 2024

Today I noticed, that the description request fails for some events that have "ß", "ü" or similar characters in them.
This results in the error "Too Many Redirects".

My Attempts To Fix This

I have tried upping the maxRedirects property of the Axios request but with no success.

I have played around with this function
axios.get("https://www.wowhead.com/de/event=634")

The URL Axios tries to request is the following:
https://www.wowhead.com/de/event=634/das-gro%C3%83%C2%9Fe-hippogryphenschl%C3%83%C2%BCpfen
which Axios does not seem to work with since this keeps redirecting. (It does work in a normal browser)

Though when I manually give Axios this URL (which i directly copied from my browser):
https://www.wowhead.com/de/event=634/das-gro%C3%9Fe-hippogryphenschl%C3%BCpfen
it does work.

Notice the additional %83%C2 which seems to break the code.

The Workaround

As you can see in my latest push 84733e0 for version v2.2.0 i have now implemented this workaround:

try {
    let description = axios.get(`https://www.wowhead.com/${locale}/event=${JSON.parse(filteredResults[i].id)}`).then(({ data }) => {
        let metaTag = data.match('<meta name="description" content="(?:.*)">', 'gi');
        return metaTag[0].replace('<meta name="description" content="', '').replace('">', '');
    });

    // Add the description to the event object and push it to the activeEvents array
    filteredResults[i].description = await description;
    filteredResults[i].descriptionLocale = locale;
    // Set a flag to indicate that the description request was successful and no fallback was used
    filteredResults[i].descriptionFallback = false;
    activeEvents.push(filteredResults[i]);


} catch {

    //Fallback to "en" if the chosen description locale request results in too many redirects
    let description = axios.get(`https://www.wowhead.com/en/event=${JSON.parse(filteredResults[i].id)}`).then(({ data }) => {
        let metaTag = data.match('<meta name="description" content="(?:.*)">', 'gi');
        return metaTag[0].replace('<meta name="description" content="', '').replace('">', '');
    });

    // Add the description to the event object and push it to the activeEvents array
    filteredResults[i].description = await description;
    filteredResults[i].descriptionLocale = "en";
    // Set a flag to indicate that the description has been replaced with a fallback
    filteredResults[i].descriptionFallback = true;
    activeEvents.push(filteredResults[i]);
}

This workaround just falls back to "en" locale, which does not seem to have this Too Many Redirects issue (at least at this moment).
It also sets the flag descriptionFallback = true; to indicate, that this description is a fallback to english.

Help Wanted!

I really want to get this working with all the different locales without issues and not with this sloppy workaround.
Maybe some of you reading this have better ideas than I have and can maybe help me with this issue.

I do appreciate everyone who creates a Pull Request to help me fix this bug.

@Roo7K1d Roo7K1d added bug Something isn't working help wanted Extra attention is needed labels Feb 23, 2024
@Roo7K1d Roo7K1d self-assigned this Feb 23, 2024
@Roo7K1d Roo7K1d pinned this issue Feb 23, 2024
@Roo7K1d
Copy link
Owner Author

Roo7K1d commented Feb 23, 2024

Edit

I noticed that after i pushed the github workflow worked with Node v18+. So it seems to be an issue with the node version (my stupid ahh still used Node 16 oof)

@Roo7K1d Roo7K1d closed this as completed Feb 23, 2024
@Roo7K1d Roo7K1d changed the title getActiveEvents("de") - Error: Too Many Redirects Fetch Event Icon URL To Add To Event Objects Feb 27, 2024
@Roo7K1d Roo7K1d changed the title Fetch Event Icon URL To Add To Event Objects getActiveEvents("de") - Error: Too Many Redirects Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant