-
Notifications
You must be signed in to change notification settings - Fork 932
chore: Standarise fetch in CLI #463
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
834be96
imp: standarize fetch in CLI
Esemesek 693573c
imp: remove commented out function
Esemesek 64f3950
Merge remote-tracking branch 'origin' into fetch
Esemesek 4550995
Change fetch a little bit
Esemesek 911c986
Fix isPackagerRunning
Esemesek 2bf2da5
Improve mocking
Esemesek 834c15c
Fix release checker
Esemesek 1890054
Fix upgrade
Esemesek da3e461
Handle status codes inside fetch
Esemesek 704920f
use logger from cli-tools
thymikee 8296696
add more details to fetch failure
thymikee 6a23314
parse text repsonse
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
packages/cli/src/commands/init/__tests__/templateName.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import nodeFetch, { | ||
| RequestInit as FetchOptions, | ||
| Response, | ||
| Request, | ||
| Headers, | ||
| } from 'node-fetch'; | ||
| import {CLIError} from './errors'; | ||
|
|
||
| async function unwrapFetchResult(response: Response) { | ||
| const data = await response.text(); | ||
|
|
||
| try { | ||
| return JSON.parse(data); | ||
| } catch (e) { | ||
| return data; | ||
| } | ||
| } | ||
|
|
||
| export default async function fetch( | ||
| url: string | Request, | ||
| options?: FetchOptions, | ||
| ): Promise<{status: number, data: any, headers: Headers}> { | ||
| const result = await nodeFetch(url, options); | ||
| const data = await unwrapFetchResult(result); | ||
|
|
||
| if (result.status >= 400) { | ||
| throw new CLIError( | ||
| `Fetch request failed with status ${result.status}: ${data}.`, | ||
| ); | ||
| } | ||
|
|
||
| return { | ||
| status: result.status, | ||
| headers: result.headers, | ||
| data, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.