Skip to content

Commit 85fed78

Browse files
committed
fix: suppress request error
close #18
1 parent 2e15560 commit 85fed78

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/index.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,25 @@ async function startDevelop() {
4545
);
4646
const rpc = async (cmd: string, args: unknown[]) => {
4747
// console.log('RPC:', cmd, args);
48-
const res = await fetch(`http://localhost:${port}/~api`, {
49-
method: 'POST',
50-
headers: {
51-
'content-type': 'application/json',
52-
},
53-
body: JSON.stringify({
54-
cmd,
55-
args,
56-
}),
57-
});
58-
if (!res.ok) {
59-
console.error(`Error: ${res.status}`);
48+
try {
49+
const res = await fetch(`http://localhost:${port}/~api`, {
50+
method: 'POST',
51+
headers: {
52+
'content-type': 'application/json',
53+
},
54+
body: JSON.stringify({
55+
cmd,
56+
args,
57+
}),
58+
});
59+
if (!res.ok) {
60+
throw new Error(`Request error: ${res.status}`);
61+
}
62+
return true;
63+
} catch (err) {
64+
console.error(err);
65+
return false;
6066
}
61-
return res.ok;
6267
};
6368
const { nvim } = workspace;
6469
const buffer = await nvim.buffer;

0 commit comments

Comments
 (0)