Skip to content

Commit

Permalink
Merge branch 'more-error-handling'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonlamb-gh committed Apr 29, 2024
2 parents e33618e + c6b3b8a commit d043338
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
91 changes: 91 additions & 0 deletions vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@
"@viz-js/viz": "^3.0.1",
"@vscode/codicons": "^0.0.32",
"@vscode/webview-ui-toolkit": "^1.4.0",
"axios": "^1.6.8",
"cytoscape": "^3.28.1",
"cytoscape-context-menus": "^4.1.0",
"cytoscape-cose-bilkent": "^4.1.0",
Expand Down
10 changes: 9 additions & 1 deletion vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ let lspClient: LanguageClient;
export async function activate(context: vscode.ExtensionContext) {
log = vscode.window.createOutputChannel("Auxon");

const apiUrl = await config.modalityUrl();
const modalitydIsAlive = await api.isModalitydReachable(apiUrl.toString());
if (!modalitydIsAlive) {
const msg =
`The Auxon Modality backend server cannot be reached at '${apiUrl}'. ` +
`If modalityd is not running locally, set the 'auxon.modalityUrl' configuration`;
throw new Error(msg);
}

// If this is a fresh install, prompt for new first user creation
await user.handleNewUserCreation();

lspClient = await lsp.activateLspClient(context);

const apiUrl = await config.modalityUrl();
const allowInsecure = await config.allowInsecureHttps();
let token = await config.userAuthToken();

Expand Down
14 changes: 14 additions & 0 deletions vscode/src/modalityApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as gen from "./generated/src/modality-api";
import createClient from "openapi-fetch";
import axios from "axios";

// See https://github.com/ajaishankar/openapi-typescript-fetch#server-side-usage
import fetch, { Headers, Request, Response } from "node-fetch";
Expand Down Expand Up @@ -75,6 +76,19 @@ export type Experiment = gen.components["schemas"]["Experiment"];

type InternalClient = ReturnType<typeof createClient<gen.paths>>;

export async function isModalitydReachable(baseUrl: string): Promise<boolean> {
if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.slice(0, -1);
}
const url = baseUrl + "/v1/alive";
try {
const _response = await axios.get(url);
} catch (_exception) {
return false;
}
return true;
}

export class Client {
client: InternalClient;

Expand Down

0 comments on commit d043338

Please sign in to comment.