Shopify / cli

Build apps, themes, and hydrogen storefronts for Shopify
https://shopify.dev
MIT License
436 stars 128 forks source link

Refresh session when 401 errors happens #4790

Closed karreiro closed 1 week ago

karreiro commented 2 weeks ago

WHY are these changes introduced?

Fixes https://github.com/Shopify/cli/issues/4618

The Assets API may return 401 statuses after running for a while, and that may happen before the session gets refreshed. To prevent the development server from terminating, if we get that status, we manually refresh the session.

WHAT is this pull request doing?

This PR solves this by calling session.refresh() when it gets a 401 error. We'd face a circular dependency if we were to get the types correctly, so this PR checks the refresh at runtime and just calls it (this will no longer be necessary with https://github.com/Shopify/cli/issues/4769 solved).

How to test your changes?

Post-release steps

N/A

Measuring impact

How do we know this change was effective? Please choose one:

Checklist

github-actions[bot] commented 2 weeks ago

Coverage report

St.:grey_question:
Category Percentage Covered / Total
🟑 Statements
72.12% (+0.08% πŸ”Ό)
8390/11633
🟑 Branches
68.56% (+0.06% πŸ”Ό)
4059/5920
🟑 Functions
71.43% (+0.06% πŸ”Ό)
2198/3077
🟑 Lines
72.53% (+0.08% πŸ”Ό)
7935/10941

Test suite run success

1901 tests passing in 867 suites.

Report generated by πŸ§ͺjest coverage report action from 45e9fa7a1c44c4701d7aaae4d6d4a348429d7774

frandiox commented 1 week ago

/snapit

github-actions[bot] commented 1 week ago

🫰✨ Thanks @frandiox! Your snapshot has been published to npm.

Test the snapshot by intalling your package globally:

pnpm i -g @shopify/cli@0.0.0-snapshot-20241106120425

After installing, validate the version by running just shopify in your terminal If the versions don't match, you might have multiple global instances installed. Use which shopify to find out which one you are running and uninstall it.

karreiro commented 1 week ago

@Shopify/app-inner-loop Could you please take a look at this one to unblock merge? πŸ™‡

karreiro commented 1 week ago

(I just rebased the branch because it got a conflict β€” it's ready to merge again)