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

"Unexpected end of JSON input" from Trakt API when username doesn't exist #415

Open
sentience opened this issue Jan 24, 2021 · 6 comments
Open

Comments

@sentience
Copy link

Trying trakt-to-letterboxd for the first time, this is what I'm getting:

$ npx trakt-to-letterboxd -u redacted
npx: installed 22 in 3.853sinvalid json response body at https://api.trakt.tv/users/redacted/watched/movies reason: Unexpected end of JSON input FetchError: invalid json response body at https://api.trakt.tv/users/redacted/watched/movies reason: Unexpected end of JSON input
at /Users/redacted/.npm/_npx/75163/lib/node_modules/trakt-to-letterboxd/node_modules/node-fetch/lib/index.js:272:32
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async fetchMovies (/Users/redacted/.npm/_npx/75163/lib/node_modules/trakt-to-letterboxd/dist/main/fetcher.js:75:23)
at async traktHistoryToCsv (/Users/redacted/.npm/_npx/75163/lib/node_modules/trakt-to-letterboxd/dist/main/index.js:40:25) {
type: 'invalid-json'
}
invalid json response body at https://api.trakt.tv/users/redacted/watchlist/movies reason: Unexpected end of JSON input FetchError: invalid json response body at https://api.trakt.tv/users/redacted/watchlist/movies reason: Unexpected end of JSON input
at /Users/redacted/.npm/_npx/75163/lib/node_modules/trakt-to-letterboxd/node_modules/node-fetch/lib/index.js:272:32
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async fetchMovies (/Users/redacted/.npm/_npx/75163/lib/node_modules/trakt-to-letterboxd/dist/main/fetcher.js:75:23)
at async traktHistoryToCsv (/Users/redacted/.npm/_npx/75163/lib/node_modules/trakt-to-letterboxd/dist/main/index.js:49:25) {
type: 'invalid-json'
}
Complete!

I can crack open the Node debugger to inspect the JSON responses if necessary, but I thought I'd make sure I'm not missing anything obvious.

@sentience
Copy link
Author

Turns out it was something obvious: I had my username wrong.

I guess this is what happens when you specify a non-existent username. Might be good to catch that and display a better error.

@sentience sentience changed the title "Unexpected end of JSON input" from Trakt API "Unexpected end of JSON input" from Trakt API when username doesn't exist Jan 24, 2021
@cbserra
Copy link

cbserra commented Jan 4, 2023

Same error occurs if the user is private (as I was -- just made myself public to run this and worked successfully)

Not sure if more verbose error codes/messages are received that could provide some more help?

@bbeesley
Copy link
Owner

bbeesley commented Jan 4, 2023

Not sure if more verbose error codes/messages are received that could provide some more help?

I'll have a quick look, but "unexpected end of json input" makes me think it's probably just an empty 404. Nevertheless it should definitely be handled more gracefully.

@cbserra
Copy link

cbserra commented Jan 4, 2023

@bbeesley Any plans to convert the JavaScript to Typescript? I pulled the code down and my VS code setup complained about the use of types in non-TS files. I started refactoring. I can work on a PR if you're interested?

@bbeesley
Copy link
Owner

bbeesley commented Jan 4, 2023

@bbeesley Any plans to convert the JavaScript to Typescript? I pulled the coffee down and my VS code setup complained about the use of types in non-TS files. I started refactoring. I can work on a PR if you're interested?

lmao, yeah, I haven't looked at this repo in ages and basically did the same thing earlier today, started refactoring. I'm at work at the moment so I've got other stuff to do right now, but after work I'll create a next branch with the stuff I started doing, I'll give you a shout when I've done that if you wanna help out.

@bbeesley
Copy link
Owner

bbeesley commented Jan 6, 2023

@cbserra ok, I've done a bunch of tidying up, migrated it to typescript, and moved the ci over to github actions. Should be in a good state now if you wanna improve the error handling or do some refactoring. I didn't change any of the functionality, just build/test/publish stuff.

fyi, I've moved it over to pnpm as well; aint nobody got time for npm ci.

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

No branches or pull requests

3 participants