bbeesley / trakt-to-letterboxd

CLI tool for publishing your trakt watched history to your letterboxd account
79 stars 5 forks source link

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

Open sentience opened 3 years ago

sentience commented 3 years ago

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 commented 3 years ago

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.

cbserra commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

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