Skip to content

Commit

Permalink
refactor fetchThemeJson
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicente Canales committed Mar 27, 2024
1 parent 05b48f1 commit cd2ca55
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,32 @@ export async function fetchThemeJson() {

try {
const response = await apiFetch( fetchOptions );
const data = JSON.stringify( response, null, 2 );
return JSON.stringify( JSON.parse( data )?.data, null, 2 );

if ( ! response?.data || 'SUCCESS' !== response?.status ) {
throw new Error(
`Failed to fetch theme data: ${
response?.message || response?.status
}`
);
}

return JSON.stringify( response?.data, null, 2 );
} catch ( e ) {
// @todo: handle error
}
}

export async function saveThemeJson() {
const fetchOptions = {
path: '/create-block-theme/v1/save-theme-data',
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
};

try {
await apiFetch( fetchOptions );
} catch ( e ) {
// @todo: handle error
}
Expand Down

0 comments on commit cd2ca55

Please sign in to comment.