sindresorhus / alfy

Create Alfred workflows with ease
MIT License
2.63k stars 104 forks source link

fetch with `json: false` is ignored? #152

Closed adamkiss closed 2 years ago

adamkiss commented 2 years ago

I'm using the alfy.fetch to fetch a HTML file I later parse. Whenever I call it with json: false, I get back the Cannot use 'GET' with body error for some reason. I tried to hunt the error down the line, but looking at the index.js, I don't see the json option read anywhere and the response always parsed as json(), so perhaps the json option is passed through to got as a body?

Edit: looking at the blame of the file, I see that for whatever reason, @jopemachine removed the option while bumping got in https://github.com/sindresorhus/alfy/commit/56aed04cff57d49635a8182af8aa696c70852bfa

Is it not supposed to be an option anymore, or is that an error?

sindresorhus commented 2 years ago

Make sure you're using the latest version: https://github.com/sindresorhus/alfy/releases/tag/v0.12.3

adamkiss commented 2 years ago

@sindresorhus I am using the latest, but instead of turning JSON parsing off, alfy passess the json: false to got, which then interprets it as request body, which then fails for GET requests.

Instead, alfy.fetch should detect the json: false, unset it, and call .response instead of .json() on https://github.com/sindresorhus/alfy/blob/8e88725417077b651a17098334afb05db84cb28c/index.js#L142

At least I think, unless fetching other formats other than JSON isn't supported anymore