Skip to content

Commit c25a86a

Browse files
log proper error msg when host is not provided when live preview enabled
1 parent 001f009 commit c25a86a

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/core",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"type": "commonjs",
55
"main": "./dist/cjs/src/index.js",
66
"types": "./dist/cjs/src/index.d.ts",

src/lib/request.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export async function getData(instance: AxiosInstance, url: string, data?: any)
1313
instance.defaults.headers.preview_token = livePreviewParams.preview_token;
1414
instance.defaults.headers.live_preview = livePreviewParams.live_preview;
1515
}
16-
17-
if (livePreviewParams.enable && livePreviewParams.live_preview && livePreviewParams.live_preview !== 'init') {
16+
if (livePreviewParams.enable) {
1817
// adds protocol so host is replaced and not appended
19-
if (livePreviewParams.host.split(0, 8) === 'https://') {
20-
instance.defaults.baseURL = livePreviewParams.host;
21-
} else {
22-
instance.defaults.baseURL = 'https://' + livePreviewParams.host;
18+
if (livePreviewParams.live_preview && livePreviewParams.live_preview !== 'init') {
19+
if (!livePreviewParams.host) {
20+
throw new Error('Host is required for live preview');
21+
}
22+
instance.defaults.baseURL = livePreviewParams.host.startsWith('https://') ? '' : 'https://' + livePreviewParams.host;
2323
}
2424
}
2525
}
@@ -30,7 +30,7 @@ export async function getData(instance: AxiosInstance, url: string, data?: any)
3030
} else {
3131
throw Error(JSON.stringify(response));
3232
}
33-
} catch (err) {
34-
throw Error(JSON.stringify(err));
33+
} catch (err: any) {
34+
throw new Error(`${err.message || JSON.stringify(err)}`);
3535
}
3636
}

0 commit comments

Comments
 (0)