@@ -25,33 +25,36 @@ import {buildTheme} from '@shopify/cli-kit/node/themes/factories'
2525import { Result , Checksum , Key , Theme , ThemeAsset , Operation } from '@shopify/cli-kit/node/themes/types'
2626import { outputDebug } from '@shopify/cli-kit/node/output'
2727import { sleep } from '@shopify/cli-kit/node/system'
28- import { ClientError } from 'graphql-request'
2928
3029export type ThemeParams = Partial < Pick < Theme , 'name' | 'role' | 'processing' | 'src' > >
3130export type AssetParams = Pick < ThemeAsset , 'key' > & Partial < Pick < ThemeAsset , 'value' | 'attachment' > >
3231
3332export 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