Skip to content

Commit 7d92406

Browse files
authored
Export webrpcErrorByCode on generated files (#25)
* Export `webrpcErrorByCode` on generated files * Add Webrpc Error codes enum * Add generated files
1 parent 330b647 commit 7d92406

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
lines changed

_examples/node-ts/server/server.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable */
22
// node-ts v1.0.0 6713366104e62b8479d628a193e2a7ca03f37edc
33
// --
4-
// Code generated by [email protected].1 with ../../../gen-typescript generator. DO NOT EDIT.
4+
// Code generated by [email protected].4 with ../../../gen-typescript generator. DO NOT EDIT.
55
//
66
// webrpc-gen -schema=service.ridl -target=../../../gen-typescript -server -out=./server/server.gen.ts
77

88
export const WebrpcHeader = "Webrpc"
99

10-
export const WebrpcHeaderValue = "[email protected].1;gen-typescript@unknown;[email protected]"
10+
export const WebrpcHeaderValue = "[email protected].4;gen-typescript@unknown;[email protected]"
1111

1212
// WebRPC description and code-gen version
1313
export const WebRPCVersion = "v1"

_examples/node-ts/webapp/client.gen.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable */
22
// node-ts v1.0.0 6713366104e62b8479d628a193e2a7ca03f37edc
33
// --
4-
// Code generated by [email protected].1 with ../../../gen-typescript generator. DO NOT EDIT.
4+
// Code generated by [email protected].4 with ../../../gen-typescript generator. DO NOT EDIT.
55
//
66
// webrpc-gen -schema=service.ridl -target=../../../gen-typescript -client -out=./webapp/client.gen.ts
77

88
export const WebrpcHeader = "Webrpc"
99

10-
export const WebrpcHeaderValue = "[email protected].1;gen-typescript@unknown;[email protected]"
10+
export const WebrpcHeaderValue = "[email protected].4;gen-typescript@unknown;[email protected]"
1111

1212
// WebRPC description and code-gen version
1313
export const WebRPCVersion = "v1"
@@ -384,7 +384,21 @@ export enum errors {
384384
WebrpcStreamFinished = 'WebrpcStreamFinished',
385385
}
386386

387-
const webrpcErrorByCode: { [code: number]: any } = {
387+
export enum WebrpcErrorCodes {
388+
WebrpcEndpoint = 0,
389+
WebrpcRequestFailed = -1,
390+
WebrpcBadRoute = -2,
391+
WebrpcBadMethod = -3,
392+
WebrpcBadRequest = -4,
393+
WebrpcBadResponse = -5,
394+
WebrpcServerPanic = -6,
395+
WebrpcInternalError = -7,
396+
WebrpcClientDisconnected = -8,
397+
WebrpcStreamLost = -9,
398+
WebrpcStreamFinished = -10,
399+
}
400+
401+
export const webrpcErrorByCode: { [code: number]: any } = {
388402
[0]: WebrpcEndpointError,
389403
[-1]: WebrpcRequestFailedError,
390404
[-2]: WebrpcBadRouteError,

_examples/sse/webapp/client.gen.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable */
22
// webrpc-sse-chat v1.0.0 a799dc63b082644f5d003c8881424546aee23a2c
33
// --
4-
// Code generated by [email protected].1 with ../../ generator. DO NOT EDIT.
4+
// Code generated by [email protected].4 with ../../ generator. DO NOT EDIT.
55
//
66
// webrpc-gen -schema=service.ridl -target=../../ -client -out=./webapp/client.gen.ts
77

88
export const WebrpcHeader = "Webrpc"
99

10-
export const WebrpcHeaderValue = "[email protected].1;@unknown;[email protected]"
10+
export const WebrpcHeaderValue = "[email protected].4;@unknown;[email protected]"
1111

1212
// WebRPC description and code-gen version
1313
export const WebRPCVersion = "v1"
@@ -554,7 +554,22 @@ export enum errors {
554554
EmptyUsername = 'EmptyUsername',
555555
}
556556

557-
const webrpcErrorByCode: { [code: number]: any } = {
557+
export enum WebrpcErrorCodes {
558+
WebrpcEndpoint = 0,
559+
WebrpcRequestFailed = -1,
560+
WebrpcBadRoute = -2,
561+
WebrpcBadMethod = -3,
562+
WebrpcBadRequest = -4,
563+
WebrpcBadResponse = -5,
564+
WebrpcServerPanic = -6,
565+
WebrpcInternalError = -7,
566+
WebrpcClientDisconnected = -8,
567+
WebrpcStreamLost = -9,
568+
WebrpcStreamFinished = -10,
569+
EmptyUsername = 100,
570+
}
571+
572+
export const webrpcErrorByCode: { [code: number]: any } = {
558573
[0]: WebrpcEndpointError,
559574
[-1]: WebrpcRequestFailedError,
560575
[-2]: WebrpcBadRouteError,

clientHelpers.go.tmpl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,16 @@ export enum errors {
110110
{{- end}}
111111
}
112112

113-
const webrpcErrorByCode: { [code: number]: any } = {
113+
export enum WebrpcErrorCodes {
114+
{{- range $_, $error := $webrpcErrors}}
115+
{{$error.Name}} = {{$error.Code}},
116+
{{- end }}
117+
{{- range $_, $error := $schemaErrors}}
118+
{{$error.Name}} = {{$error.Code}},
119+
{{- end }}
120+
}
121+
122+
export const webrpcErrorByCode: { [code: number]: any } = {
114123
{{- range $_, $error := $webrpcErrors}}
115124
[{{$error.Code}}]: {{$error.Name}}Error,
116125
{{- end }}

0 commit comments

Comments
 (0)