Skip to content

Commit f1bbbcc

Browse files
authored
Merge pull request #7012 from Shopify/lk-fix-org-not-found-error
Fix orgAndApps crash when organization is not found
2 parents c0efc0f + 0bef4a6 commit f1bbbcc

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/app': patch
3+
---
4+
5+
Fix crash when organization is not found in app-management-client by throwing NoOrgError instead of accessing properties on undefined

packages/app/src/cli/utilities/developer-platform-client/app-management-client.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,28 @@ describe('organizations', () => {
17721772
})
17731773
})
17741774

1775+
describe('orgAndApps', () => {
1776+
test('throws NoOrgError if organization is not found', async () => {
1777+
// Given
1778+
const client = AppManagementClient.getInstance()
1779+
client.businessPlatformToken = () => Promise.resolve('business-platform-token')
1780+
client.session = () => Promise.resolve({token: '', accountInfo: {type: 'UnknownAccount'}}) as any
1781+
1782+
vi.mocked(businessPlatformRequestDoc).mockResolvedValue({
1783+
currentUserAccount: {organization: null},
1784+
})
1785+
vi.mocked(appManagementRequestDoc).mockResolvedValue({
1786+
appsConnection: {edges: [], pageInfo: {hasNextPage: false}},
1787+
})
1788+
1789+
// When
1790+
const got = () => client.orgAndApps('1')
1791+
1792+
// Then
1793+
await expect(got).rejects.toThrow('No Organization found')
1794+
})
1795+
})
1796+
17751797
describe('singleton pattern', () => {
17761798
test('getInstance returns the same instance', () => {
17771799
// Given/When

packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
OrganizationExpFlagsQueryVariables,
88
OrganizationExpFlags,
99
} from '../../api/graphql/business-platform-organizations/generated/organization_exp_flags.js'
10+
import {NoOrgError} from '../../services/dev/fetch.js'
1011
import {environmentVariableNames} from '../../constants.js'
1112
import {RemoteSpecification} from '../../api/graphql/extension_specifications.js'
1213
import {
@@ -411,7 +412,11 @@ export class AppManagementClient implements DeveloperPlatformClient {
411412
this.orgFromId(organizationId),
412413
this.appsForOrg(organizationId),
413414
])
414-
return {organization: organization!, apps, hasMorePages}
415+
if (!organization) {
416+
const {accountInfo} = await this.session()
417+
throw new NoOrgError(accountInfo, organizationId)
418+
}
419+
return {organization, apps, hasMorePages}
415420
}
416421

417422
async appsForOrg(organizationId: string, term = ''): Promise<Paginateable<{apps: MinimalOrganizationApp[]}>> {

0 commit comments

Comments
 (0)