Skip to content

Commit 4266f60

Browse files
authored
Merge pull request #5200 from Shopify/fix-5192
Fix `shopify theme dev` to no longer fail when development themes expire in internationalized stores
2 parents 14612d3 + 1a5aec2 commit 4266f60

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

.changeset/lemon-pants-add.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@shopify/cli-kit': patch
3+
'@shopify/theme': patch
4+
---
5+
6+
Fix `shopify theme dev` to no longer fail when development themes expire in internationalized stores

packages/cli-kit/src/public/node/themes/api.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('fetchTheme', () => {
5959
test('returns undefined when a theme is not found', async () => {
6060
const errorResponse = {
6161
status: 200,
62-
errors: [{message: 'Theme does not exist'} as any],
62+
errors: [{message: 'Tema não existe'} as any],
6363
}
6464
vi.mocked(adminRequestDoc).mockRejectedValue(new ClientError(errorResponse, {query: ''}))
6565

packages/cli-kit/src/public/node/themes/api.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,36 @@ import {buildTheme} from '@shopify/cli-kit/node/themes/factories'
2525
import {Result, Checksum, Key, Theme, ThemeAsset, Operation} from '@shopify/cli-kit/node/themes/types'
2626
import {outputDebug} from '@shopify/cli-kit/node/output'
2727
import {sleep} from '@shopify/cli-kit/node/system'
28-
import {ClientError} from 'graphql-request'
2928

3029
export type ThemeParams = Partial<Pick<Theme, 'name' | 'role' | 'processing' | 'src'>>
3130
export type AssetParams = Pick<ThemeAsset, 'key'> & Partial<Pick<ThemeAsset, 'value' | 'attachment'>>
3231

3332
export async function fetchTheme(id: number, session: AdminSession): Promise<Theme | undefined> {
33+
const gid = composeThemeGid(id)
34+
3435
try {
35-
const response = await adminRequestDoc(GetTheme, session, {id: composeThemeGid(id)}, undefined, {
36+
const {theme} = await adminRequestDoc(GetTheme, session, {id: gid}, undefined, {
3637
handleErrors: false,
3738
})
38-
const {theme} = response
39-
if (!theme) {
40-
return undefined
41-
}
42-
return buildTheme({
43-
id: parseGid(theme.id),
44-
processing: theme.processing,
45-
role: theme.role.toLowerCase(),
46-
name: theme.name,
47-
})
48-
} catch (error) {
49-
if (error instanceof ClientError) {
50-
if (error.response?.errors?.[0]?.message === 'Theme does not exist') {
51-
return undefined
52-
}
39+
40+
if (theme) {
41+
return buildTheme({
42+
id: parseGid(theme.id),
43+
processing: theme.processing,
44+
role: theme.role.toLowerCase(),
45+
name: theme.name,
46+
})
5347
}
54-
throw new AbortError(`Failed to fetch theme: ${id}`)
48+
49+
// eslint-disable-next-line no-catch-all/no-catch-all
50+
} catch (_error) {
51+
/**
52+
* Consumers of this and other theme APIs in this file expect either a theme
53+
* or `undefined`.
54+
*
55+
* Error handlers should not inspect GraphQL error messages directly, as
56+
* they are internationalized.
57+
*/
5558
}
5659
}
5760

0 commit comments

Comments
 (0)