🔊 better error handling for remote config download
This commit is contained in:
parent
25f3d7acc9
commit
4c8fe9da3a
1 changed files with 31 additions and 13 deletions
|
|
@ -93,19 +93,37 @@ export class RemoteConfigSync {
|
|||
}
|
||||
|
||||
async sync(userToken: string, remoteConfigServerUrl: URL) {
|
||||
const response = await fetch(new URL("sync", remoteConfigServerUrl).href, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${userToken}`,
|
||||
},
|
||||
});
|
||||
try {
|
||||
const response = await fetch(
|
||||
new URL("sync", remoteConfigServerUrl).href,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${userToken}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const { configJson, configJs } = await response.json();
|
||||
fs.writeFileSync(
|
||||
getConfigJsonPathForRemote(remoteConfigServerUrl),
|
||||
configJson
|
||||
);
|
||||
fs.writeFileSync(getConfigJsPathForRemote(remoteConfigServerUrl), configJs);
|
||||
configHandler.reloadConfig();
|
||||
if (!response.ok) {
|
||||
vscode.window.showErrorMessage(
|
||||
`Failed to sync remote config (HTTP ${response.status}): ${response.statusText}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const { configJson, configJs } = await response.json();
|
||||
|
||||
fs.writeFileSync(
|
||||
getConfigJsonPathForRemote(remoteConfigServerUrl),
|
||||
configJson
|
||||
);
|
||||
fs.writeFileSync(
|
||||
getConfigJsPathForRemote(remoteConfigServerUrl),
|
||||
configJs
|
||||
);
|
||||
configHandler.reloadConfig();
|
||||
} catch (e) {
|
||||
vscode.window.showErrorMessage(`Failed to sync remote config: ${e}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue