Skip to content

Commit

Permalink
Throw BugError if response is improperly formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
amcaplan committed Nov 24, 2024
1 parent db183b7 commit c55df5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {CLI_KIT_VERSION} from '@shopify/cli-kit/common/version'
import {fetch} from '@shopify/cli-kit/node/http'
import {businessPlatformOrganizationsRequest} from '@shopify/cli-kit/node/api/business-platform'
import {appManagementRequestDoc} from '@shopify/cli-kit/node/api/app-management'
import {BugError} from '@shopify/cli-kit/node/error'

vi.mock('@shopify/cli-kit/node/http')
vi.mock('@shopify/cli-kit/node/api/business-platform')
Expand Down Expand Up @@ -241,4 +242,17 @@ describe('searching for apps', () => {
hasMorePages: false,
})
})

test("Throws a BugError if the response doesn't contain the expected data", async () => {
// Given
const orgId = '1'
vi.mocked(appManagementRequestDoc).mockResolvedValueOnce({})

// When
const client = new AppManagementClient()
client.token = () => Promise.resolve('token')

// Then
await expect(client.appsForOrg(orgId)).rejects.toThrow(BugError)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class AppManagementClient implements DeveloperPlatformClient {
}
const result = await appManagementRequestDoc(organizationId, query, await this.token(), variables)
if (!result.appsConnection) {
throw new AbortError('Server failed to retrieve apps')
throw new BugError('Server failed to retrieve apps')
}
const minimalOrganizationApps = result.appsConnection.edges.map((edge) => {
const app = edge.node
Expand Down

0 comments on commit c55df5d

Please sign in to comment.