Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions _examples/node-ts/webapp/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class ExampleService implements ExampleService {
return {}
})
}, (error) => {
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
})
}

Expand All @@ -156,7 +156,7 @@ export class ExampleService implements ExampleService {
}
})
}, (error) => {
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
})
}

Expand All @@ -180,13 +180,9 @@ const buildResponse = (res: Response): Promise<any> => {
try {
data = JSON.parse(text)
} catch(error) {
let message = ''
if (error instanceof Error) {
message = error.message
}
throw WebrpcBadResponseError.new({
status: res.status,
cause: `JSON.parse(): ${message}: response text: ${text}`},
cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`},
)
}
if (!res.ok) {
Expand Down
18 changes: 4 additions & 14 deletions _examples/sse/webapp/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class Chat implements Chat {
return {}
})
}, (error) => {
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
})
}

Expand Down Expand Up @@ -237,11 +237,6 @@ const sseResponse = async (
lastReadTime = Date.now();
buffer += decoder.decode(value, {stream: true});
} catch (error) {
let message = "";
if (error instanceof Error) {
message = error.message;
}

if (error instanceof DOMException && error.name === "AbortError") {
onError(
WebrpcClientAbortedError.new({
Expand All @@ -255,7 +250,7 @@ const sseResponse = async (
} else {
onError(
WebrpcStreamLostError.new({
cause: `reader.read(): ${message}`,
cause: `reader.read(): ${error instanceof Error ? error.message : String(error)}`,
}),
retryFetch
);
Expand Down Expand Up @@ -291,8 +286,7 @@ const sseResponse = async (
onError(
WebrpcBadResponseError.new({
status: res.status,
// @ts-ignore
cause: `JSON.parse(): ${error.message}`,
cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}`,
}),
retryFetch
);
Expand Down Expand Up @@ -330,13 +324,9 @@ const buildResponse = (res: Response): Promise<any> => {
try {
data = JSON.parse(text)
} catch(error) {
let message = ''
if (error instanceof Error) {
message = error.message
}
throw WebrpcBadResponseError.new({
status: res.status,
cause: `JSON.parse(): ${message}: response text: ${text}`},
cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`},
)
}
if (!res.ok) {
Expand Down
2 changes: 1 addition & 1 deletion client.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class {{.Name}} implements {{.Name}} {
{{- else }}return {}{{- end }}
})
}, (error) => {
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}` })
})
}
{{end -}}
Expand Down
6 changes: 1 addition & 5 deletions clientHelpers.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ const buildResponse = (res: Response): Promise<any> => {
try {
data = JSON.parse(text)
} catch(error) {
let message = ''
if (error instanceof Error) {
message = error.message
}
throw WebrpcBadResponseError.new({
status: res.status,
cause: `JSON.parse(): ${message}: response text: ${text}`},
cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`},
)
}
if (!res.ok) {
Expand Down
10 changes: 2 additions & 8 deletions clientSSE.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ const sseResponse = async (
lastReadTime = Date.now();
buffer += decoder.decode(value, {stream: true});
} catch (error) {
let message = "";
if (error instanceof Error) {
message = error.message;
}

if (error instanceof DOMException && error.name === "AbortError") {
onError(
WebrpcClientAbortedError.new({
Expand All @@ -70,7 +65,7 @@ const sseResponse = async (
} else {
onError(
WebrpcStreamLostError.new({
cause: `reader.read(): ${message}`,
cause: `reader.read(): ${error instanceof Error ? error.message : String(error)}`,
}),
retryFetch
);
Expand Down Expand Up @@ -106,8 +101,7 @@ const sseResponse = async (
onError(
WebrpcBadResponseError.new({
status: res.status,
// @ts-ignore
cause: `JSON.parse(): ${error.message}`,
cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}`,
}),
retryFetch
);
Expand Down