trakt-to-letterboxd icon indicating copy to clipboard operation
trakt-to-letterboxd copied to clipboard

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

Open sentience opened this issue 3 years ago • 6 comments

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 avatar Jan 24 '21 11:01 sentience

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 avatar Jan 24 '21 11:01 sentience

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?

cbserra avatar Jan 04 '23 09:01 cbserra

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.

bbeesley avatar Jan 04 '23 10:01 bbeesley

@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?

cbserra avatar Jan 04 '23 12:01 cbserra

@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 avatar Jan 04 '23 14:01 bbeesley

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

bbeesley avatar Jan 06 '23 13:01 bbeesley