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

FetchError: invalid-json #1277

Closed
l3nnartt opened this issue Sep 7, 2021 · 6 comments
Closed

FetchError: invalid-json #1277

l3nnartt opened this issue Sep 7, 2021 · 6 comments
Labels

Comments

@l3nnartt
Copy link

l3nnartt commented Sep 7, 2021

I have a Discord Bot and on my Windows 10 64x PC it works fine, but on my VM Debian 10 Server i got the following error and I dont know why.
If i run on my computer(Windows 10 VSC Debugger) the

image

but on my VM (Debian 10)

image

tbh i dont know why it works on my pc fine and on my server i got the error with the same packages and versions

Error:

/home/lennart/Discordbots/v2/node_modules/node-fetch/lib/index.js:272
                                return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
                                                           ^
FetchError: invalid json response body at https://karmatop.de/addon/pxl-api.php?name=L3nnart_ reason: Unexpected token < in JSON at position 0
    at /home/lennart/Discordbots/v2/node_modules/node-fetch/lib/index.js:272:32
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  type: 'invalid-json'
}

Example Code

const url = `https://karmatop.de/addon/pxl-api.php?name=` + spieler; //spieler is a variable/argument from the discord bot, for example  "L3nnart_"
            fetch(url, {
                method: "GET",
                headers: {
                    Accept: "application/json",
                },
            })

Your Environment

software version
node-fetch 2.6.1
node 16.8
npm 7.21.0
Operating System Deabian/Windows
@l3nnartt
Copy link
Author

l3nnartt commented Sep 7, 2021

cloudflare bot protection bruh moment

@autukill
Copy link

autukill commented Oct 19, 2021

My nodejs app recently crashed due to node-fetch, The exception is the same as you

@jimmywarting
Copy link
Collaborator

thinking if it might be a BOM token in the beginning...?
could you check what the text / Uint8array response is?

@Champkinz
Copy link

bump

@jimmywarting
Copy link
Collaborator

jimmywarting commented Mar 11, 2022

Bumping the wrong issue... should maybe bump #541 with a potential fix: #1482

@Champkinz
Copy link

Bumping the wrong issue... should maybe bump #541 with a potential fix: #1482

Thank you for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants