Skip to content

Commit 134a906

Browse files
authored
Merge pull request #637 from isc-bsaviano/fix-391
2 parents 73c9499 + afe2642 commit 134a906

File tree

4 files changed

+39
-26
lines changed

4 files changed

+39
-26
lines changed

src/api/index.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
checkConnection,
1414
schemas,
1515
} from "../extension";
16-
import { currentWorkspaceFolder, outputConsole, outputChannel } from "../utils";
16+
import { currentWorkspaceFolder, outputConsole } from "../utils";
1717

1818
const DEFAULT_API_VERSION = 1;
1919
import * as Atelier from "./atelier";
@@ -337,18 +337,16 @@ export class AtelierAPI {
337337
return this.cookies;
338338
}
339339

340-
if (!response.ok) {
341-
throw { statusCode: response.status, message: response.statusText };
342-
}
343-
344340
const buffer = await response.buffer();
345341
const data: Atelier.Response = JSON.parse(buffer.toString("utf-8"));
346342

347-
/// decode encoded content
343+
// Decode encoded content
348344
if (data.result && data.result.enc && data.result.content) {
349345
data.result.enc = false;
350346
data.result.content = Buffer.from(data.result.content.join(""), "base64");
351347
}
348+
349+
// Handle console output
352350
if (data.console) {
353351
// Let studio actions handle their console output
354352
const isStudioAction =
@@ -360,18 +358,21 @@ export class AtelierAPI {
360358
outputConsole(data.console);
361359
}
362360
}
361+
362+
// Handle any errors
363+
if (data.status.summary !== "") {
364+
// This is a 500 server error or a query request with malformed SQL
365+
throw { statusCode: response.status, message: response.statusText, errorText: data.status.summary };
366+
}
363367
if (data.result.status && data.result.status !== "") {
364-
const status: string = data.result.status;
365-
outputChannel.appendLine(status);
366-
throw new Error(data.result.status);
368+
// This is a 4XX error on a doc request
369+
throw { statusCode: response.status, message: response.statusText, errorText: data.result.status };
367370
}
368-
if (data.status.summary) {
369-
throw new Error(data.status.summary);
370-
} else if (data.result.status) {
371-
throw new Error(data.result.status);
372-
} else {
373-
return data;
371+
if (response.status >= 400) {
372+
// The request errored out, but didn't give us an error string back
373+
throw { statusCode: response.status, message: response.statusText, errorText: "" };
374374
}
375+
return data;
375376
} catch (error) {
376377
if (error.code === "ECONNREFUSED") {
377378
authRequestMap.delete(target);

src/commands/compile.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ async function importFile(file: CurrentFile, ignoreConflict?: boolean): Promise<
9494
checkChangedOnServer(file, true);
9595
})
9696
.catch((error) => {
97-
if (error.statusCode == 400) {
98-
outputChannel.appendLine(error.error.result.status);
99-
vscode.window.showErrorMessage(error.error.result.status);
100-
return Promise.reject();
101-
}
10297
if (error.statusCode == 409) {
10398
return vscode.window
10499
.showErrorMessage(
@@ -140,9 +135,18 @@ What do you want to do?`,
140135
}
141136
return Promise.reject();
142137
});
138+
} else {
139+
if (error.errorText && error.errorText !== "") {
140+
outputChannel.appendLine("\n" + error.errorText);
141+
vscode.window.showErrorMessage(
142+
`Failed to save file '${file.name}' on the server. Check output channel for details.`,
143+
"Dismiss"
144+
);
145+
} else {
146+
vscode.window.showErrorMessage(`Failed to save file '${file.name}' on the server.`, "Dismiss");
147+
}
148+
return Promise.reject();
143149
}
144-
vscode.window.showErrorMessage(error.message);
145-
return Promise.reject();
146150
});
147151
}
148152

src/commands/viewOthers.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from "vscode";
22
import { AtelierAPI } from "../api";
33
import { config } from "../extension";
44
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
5-
import { currentFile } from "../utils";
5+
import { currentFile, outputChannel } from "../utils";
66

77
export async function viewOthers(forceEditable = false): Promise<void> {
88
const file = currentFile();
@@ -155,6 +155,7 @@ export async function viewOthers(forceEditable = false): Promise<void> {
155155
.then((info) => {
156156
const listOthers = getOthers(info) || [];
157157
if (!listOthers.length) {
158+
vscode.window.showInformationMessage("There are no other documents to open.", "Dismiss");
158159
return;
159160
}
160161
if (listOthers.length === 1) {
@@ -165,5 +166,12 @@ export async function viewOthers(forceEditable = false): Promise<void> {
165166
});
166167
}
167168
})
168-
.catch((err) => console.error(err));
169+
.catch((err) => {
170+
if (err.errorText && err.errorText !== "") {
171+
outputChannel.appendLine("\n" + err.errorText);
172+
vscode.window.showErrorMessage(`Failed to get other documents. Check output channel for details.`, "Dismiss");
173+
} else {
174+
vscode.window.showErrorMessage(`Failed to get other documents.`, "Dismiss");
175+
}
176+
});
169177
}

src/providers/FileSystemProvider/FileSystemProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
225225
)
226226
.catch((error) => {
227227
// Throw all failures
228-
if (error.error?.result?.status) {
229-
throw vscode.FileSystemError.Unavailable(error.error.result.status);
228+
if (error.errorText && error.errorText !== "") {
229+
throw vscode.FileSystemError.Unavailable(error.errorText);
230230
}
231231
throw vscode.FileSystemError.Unavailable(error.message);
232232
})

0 commit comments

Comments
 (0)