Skip to content

Commit

Permalink
Merge pull request #4718 from Shopify/extra-logging-for-store-connect…
Browse files Browse the repository at this point in the history
…ion-error

Log more information for store connection issues
  • Loading branch information
shauns authored Oct 23, 2024
2 parents 2b6451b + 58862fd commit 5b3cd4d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/cli-kit/src/public/node/api/admin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('admin-graphql-api', () => {
expect(graphqlRequest).toHaveBeenLastCalledWith({
query: 'query',
api: 'Admin',
url: 'https://store/admin/api/2022-01/graphql.json',
url: 'https://store.myshopify.com/admin/api/2022-01/graphql.json',
token,
variables: {variables: 'variables'},
})
Expand Down
20 changes: 16 additions & 4 deletions packages/cli-kit/src/public/node/api/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {BugError, AbortError} from '../error.js'
import {restRequestBody, restRequestHeaders, restRequestUrl} from '../../../private/node/api/rest.js'
import {fetch} from '../http.js'
import {PublicApiVersions} from '../../../cli/api/graphql/admin/generated/public_api_versions.js'
import {normalizeStoreFqdn} from '../context/fqdn.js'
import {ClientError, Variables} from 'graphql-request'
import {TypedDocumentNode} from '@graphql-typed-document-node/core'

Expand All @@ -19,7 +20,8 @@ import {TypedDocumentNode} from '@graphql-typed-document-node/core'
export async function adminRequest<T>(query: string, session: AdminSession, variables?: GraphQLVariables): Promise<T> {
const api = 'Admin'
const version = await fetchLatestSupportedApiVersion(session)
const url = adminUrl(session.storeFqdn, version)
const store = await normalizeStoreFqdn(session.storeFqdn)
const url = adminUrl(store, version)
return graphqlRequest({query, api, url, token: session.token, variables})
}

Expand All @@ -44,8 +46,9 @@ export async function adminRequestDoc<TResult, TVariables extends Variables>(
if (!version) {
apiVersion = await fetchLatestSupportedApiVersion(session)
}
const store = await normalizeStoreFqdn(session.storeFqdn)
const opts = {
url: adminUrl(session.storeFqdn, apiVersion),
url: adminUrl(store, apiVersion),
api: 'Admin',
token: session.token,
}
Expand Down Expand Up @@ -99,8 +102,17 @@ async function fetchApiVersions(session: AdminSession): Promise<ApiVersion[]> {
)})`,
outputContent`If you're not the owner, create a dev store staff account for yourself`,
)
} else if (error instanceof ClientError) {
throw new BugError(
`Unknown client error connecting to your store ${session.storeFqdn}: ${error.message} ${error.response.status} ${error.response.data}`,
)
} else {
throw new BugError(
`Unknown error connecting to your store ${session.storeFqdn}: ${
error instanceof Error ? error.message : String(error)
}`,
)
}
throw new BugError(`Unknown error connecting to your store`)
}
}

Expand All @@ -112,7 +124,7 @@ async function fetchApiVersions(session: AdminSession): Promise<ApiVersion[]> {
* @returns - Admin API URL.
*/
export function adminUrl(store: string, version: string | undefined): string {
const realVersion = version || 'unstable'
const realVersion = version ?? 'unstable'
return `https://${store}/admin/api/${realVersion}/graphql.json`
}

Expand Down

0 comments on commit 5b3cd4d

Please sign in to comment.