Unnamed repository; edit this file 'description' to name the repository.
editor/code: Assert types in catch in `sendRequestWithRetry()` properly
Tetsuharu Ohzeki 2023-07-10
parent 2f6d545 · commit fd31006
-rw-r--r--editors/code/src/util.ts20
1 files changed, 12 insertions, 8 deletions
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts
index b6b779e266..688e3873ab 100644
--- a/editors/code/src/util.ts
+++ b/editors/code/src/util.ts
@@ -69,20 +69,24 @@ export async function sendRequestWithRetry<TParam, TRet>(
return await (token
? client.sendRequest(reqType, param, token)
: client.sendRequest(reqType, param));
- } catch (error) {
+ } catch (error: unknown) {
if (delay === null) {
log.warn("LSP request timed out", { method: reqType.method, param, error });
throw error;
}
- if (error.code === lc.LSPErrorCodes.RequestCancelled) {
- throw error;
- }
- if (error.code !== lc.LSPErrorCodes.ContentModified) {
- log.warn("LSP request failed", { method: reqType.method, param, error });
- throw error;
+ if (error instanceof lc.ResponseError) {
+ switch (error.code) {
+ case lc.LSPErrorCodes.RequestCancelled:
+ throw error;
+ case lc.LSPErrorCodes.ContentModified:
+ await sleep(delay);
+ continue;
+ }
}
- await sleep(delay);
+
+ log.warn("LSP request failed", { method: reqType.method, param, error });
+ throw error;
}
}
throw "unreachable";