Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tame-tips-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-kit': patch
---

Throw descriptive AbortErrors during expected authorization errors
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {identityFqdn} from '../../../public/node/context/fqdn.js'
import {shopifyFetch} from '../../../public/node/http.js'
import {isTTY} from '../../../public/node/ui.js'
import {err, ok} from '../../../public/node/result.js'
import {AbortError} from '../../../public/node/error.js'
import {isCI} from '../../../public/node/system.js'
import {beforeEach, describe, expect, test, vi} from 'vitest'
import {Response} from 'node-fetch'
Expand Down Expand Up @@ -181,4 +182,26 @@ describe('pollForDeviceAuthorization', () => {
await expect(got).rejects.toThrow()
expect(exchangeDeviceCodeForAccessToken).toBeCalledTimes(3)
})

test('when polling, if an access denied error is received, stop polling and throw AbortError', async () => {
// Given
vi.mocked(exchangeDeviceCodeForAccessToken).mockResolvedValueOnce(err('access_denied'))

// When
const got = pollForDeviceAuthorization('device_code', 0.05)

// Then
await expect(got).rejects.toThrow(new AbortError(`Device authorization failed: Access denied.`))
})

test('when polling, if an expired token error is received, stop polling and throw AbortError', async () => {
// Given
vi.mocked(exchangeDeviceCodeForAccessToken).mockResolvedValueOnce(err('expired_token'))

// When
const got = pollForDeviceAuthorization('device_code', 0.05)

// Then
await expect(got).rejects.toThrow(new AbortError(`Device authorization failed: Token expired. Please try again.`))
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ export async function pollForDeviceAuthorization(code: string, interval = 5): Pr
startPolling()
return
case 'access_denied':
reject(new AbortError(`Device authorization failed: Access denied.`))
return
case 'expired_token':
reject(new AbortError(`Device authorization failed: Token expired. Please try again.`))
return
case 'unknown_failure': {
reject(new Error(`Device authorization failed: ${error}`))
}
Expand Down
Loading