Skip to content

Commit

Permalink
Use zod for parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
vitvakatu committed Oct 31, 2023
1 parent 03ffc54 commit c031efd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/gui2/shared/languageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Client } from '@open-rpc/client-js'
import { ObservableV2 } from 'lib0/observable'
import { uuidv4 } from 'lib0/random'
import { SHA3 } from 'sha3'
import { z } from 'zod'
import type {
Checksum,
ContextId,
Expand Down Expand Up @@ -129,10 +130,9 @@ export class LanguageServer extends ObservableV2<Notifications> {
}
return await this.client.request({ method, params }, RPC_TIMEOUT_MS)
} catch (e) {
if (e && typeof e === 'object' && 'code' in e && 'message' in e && typeof e.code === 'number' && typeof e.message === 'string') {
const data = 'data' in e ? e.data : undefined
const remoteError = new RemoteRpcError(e.code, e.message, data)
throw new LsRpcError(remoteError, method, params)
const remoteError = RemoteRpcErrorSchema.safeParse(e)
if (remoteError.success) {
throw new LsRpcError(new RemoteRpcError(remoteError.data), method, params)
} else if (e instanceof Error) {
throw new LsRpcError(e, method, params)
}
Expand Down

0 comments on commit c031efd

Please sign in to comment.