Skip to content

Commit a2c99eb

Browse files
authored
Address post-merge deploy PR comments. (#271)
1 parent 8cb5afb commit a2c99eb

2 files changed

Lines changed: 14 additions & 20 deletions

File tree

src/observableApiClient.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class ObservableApiClient {
7777
method: "GET",
7878
headers: this._apiHeaders
7979
});
80-
if (response.status !== 200) {
80+
if (!response.ok) {
8181
throw new HttpError("Unexpected response status", response.status);
8282
}
8383
const responseJson = await response.json();
@@ -91,7 +91,7 @@ export class ObservableApiClient {
9191
headers: [...this._apiHeaders, ["Content-Type", "application/json"]],
9292
body: JSON.stringify({slug, workspace})
9393
});
94-
if (response.status !== 200) {
94+
if (!response.ok) {
9595
throw new HttpError("Unexpected response status", response.status);
9696
}
9797
const responseJson = await response.json();
@@ -105,7 +105,7 @@ export class ObservableApiClient {
105105
headers: [...this._apiHeaders, ["Content-Type", "application/json"]],
106106
body: JSON.stringify({})
107107
});
108-
if (response.status !== 200) {
108+
if (!response.ok) {
109109
throw new HttpError("Unexpected response status", response.status);
110110
}
111111
const responseJson = await response.json();
@@ -127,7 +127,7 @@ export class ObservableApiClient {
127127
body
128128
});
129129

130-
if (response.status !== 200 && response.status !== 204) {
130+
if (!response.ok) {
131131
throw new HttpError("Unexpected response status", response.status);
132132
}
133133
}
@@ -141,7 +141,7 @@ export class ObservableApiClient {
141141
body: JSON.stringify({})
142142
});
143143

144-
if (response.status !== 200 && response.status !== 204) {
144+
if (!response.ok) {
145145
throw new HttpError("Unexpected response status", response.status);
146146
}
147147
}

src/toolConfig.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import os from "node:os";
33
import path from "node:path";
44
import {isEnoent} from "./error.js";
55

6-
const observableConfigName = ".observablehq";
7-
interface ObservableConfig {
6+
const userConfigName = ".observablehq";
7+
interface UserConfig {
88
auth?: {
99
id: string;
1010
key: string;
@@ -20,14 +20,14 @@ export interface DeployConfig {
2020
}
2121

2222
export async function getObservableApiKey(): Promise<string | null> {
23-
const {config} = await loadObservableConfig();
23+
const {config} = await loadUserConfig();
2424
return config.auth?.key ?? null;
2525
}
2626

2727
export async function setObservableApiKey(id: string, key: string): Promise<void> {
28-
const {config, configPath} = await loadObservableConfig();
28+
const {config, configPath} = await loadUserConfig();
2929
config.auth = {id, key};
30-
await writeObservableConfig({config, configPath});
30+
await writeUserConfig({config, configPath});
3131
}
3232

3333
export async function getDeployConfig(sourceRoot: string): Promise<DeployConfig | null> {
@@ -48,10 +48,10 @@ export async function setDeployConfig(sourceRoot: string, newConfig: DeployConfi
4848
await fs.writeFile(deployConfigPath, JSON.stringify(merged, null, 2));
4949
}
5050

51-
async function loadObservableConfig(): Promise<{configPath: string; config: ObservableConfig}> {
51+
async function loadUserConfig(): Promise<{configPath: string; config: UserConfig}> {
5252
let cursor = path.resolve(process.cwd());
5353
while (true) {
54-
const configPath = path.join(cursor, observableConfigName);
54+
const configPath = path.join(cursor, userConfigName);
5555
let content: string | null = null;
5656
try {
5757
content = await fs.readFile(configPath, "utf8");
@@ -71,15 +71,9 @@ async function loadObservableConfig(): Promise<{configPath: string; config: Obse
7171
}
7272
}
7373

74-
return {config: {}, configPath: path.join(os.homedir(), observableConfigName)};
74+
return {config: {}, configPath: path.join(os.homedir(), userConfigName)};
7575
}
7676

77-
async function writeObservableConfig({
78-
configPath,
79-
config
80-
}: {
81-
configPath: string;
82-
config: ObservableConfig;
83-
}): Promise<void> {
77+
async function writeUserConfig({configPath, config}: {configPath: string; config: UserConfig}): Promise<void> {
8478
await fs.writeFile(configPath, JSON.stringify(config, null, 2));
8579
}

0 commit comments

Comments
 (0)