Skip to content

Commit

Permalink
Add check for error type (#8)
Browse files Browse the repository at this point in the history
* Add check for error instanceof error

* Regenerate client with new error

* Add ts check to tests

* Regenearte client contract with v0.11

* Fix ts-check in pipline

* Remove wrong tsc package
  • Loading branch information
AlexanderKolberg authored Jul 19, 2023
1 parent c9ed0dd commit f50891a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Git diff of regenerated files
run: cd _examples && make diff

webrpc-interoperability:
webrpc-tests:
strategy:
matrix:
webrpc-version: [v0.11.0]
Expand All @@ -55,3 +55,5 @@ jobs:
run: cd tests && echo "$PWD/bin/${{ matrix.webrpc-version }}" >> $GITHUB_PATH
- name: Run interoperability tests
run: cd tests && ./test.sh
- name: Run typescript check
run: cd tests && npm run ts-check
6 changes: 5 additions & 1 deletion _examples/node-ts/webapp/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,13 @@ 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(): ${error.message || ''}: response text: ${text}`},
cause: `JSON.parse(): ${message}: response text: ${text}`},
)
}
if (!res.ok) {
Expand Down
6 changes: 5 additions & 1 deletion clientHelpers.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ 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(): ${error.message || ''}: response text: ${text}`},
cause: `JSON.parse(): ${message}: response text: ${text}`},
)
}
if (!res.ok) {
Expand Down
24 changes: 22 additions & 2 deletions tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"main": "index.js",
"scripts": {
"test": "./test.sh",
"vitest": "./node_modules/.bin/vitest run --reporter verbose --dir ./"
"vitest": "./node_modules/.bin/vitest run --reporter verbose --dir ./",
"prets-check": "webrpc-gen -schema=./test.ridl -target=../ -client -out=./client.ts",
"ts-check": "tsc --noEmit ./client.ts"
},
"repository": {
"type": "git",
Expand All @@ -18,6 +20,7 @@
},
"homepage": "https://github.com/webrpc/gen-typescript#readme",
"devDependencies": {
"typescript": "^5.1.6",
"vitest": "^0.25.6"
},
"engines": {
Expand Down

0 comments on commit f50891a

Please sign in to comment.