Skip to content

Commit 590b5d0

Browse files
authored
HTTP/TS: Fix response type checks throwing on certain inputs (#788)
## Usage and product changes In the HTTP/TS driver, `isApiErrorResponse` and `isOkResponse` should never throw errors anymore for any input. ## Motivation Although their input is theoretically restricted, in practice errors in TypeScript usually have the `any` type when they're thrown from HTTP libraries such as `fetch`. ## Implementation Check that the input is actually an object before scanning it
1 parent d89b208 commit 590b5d0

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

http-ts/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ checkstyle_test(
106106
"tool/**/*",
107107
]),
108108
exclude = glob([
109+
".npmrc",
109110
"**/*.json",
110111
"**/*.md",
111112
"pnpm-lock.yaml",

http-ts/src/response.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ export function isApiError(err: any): err is ApiError {
119119
export type ApiResponse<OK_RES = {} | null> = ApiOkResponse<OK_RES> | ApiErrorResponse;
120120

121121
export function isOkResponse<OK_RES>(res: ApiResponse<OK_RES>): res is ApiOkResponse<OK_RES> {
122-
return "ok" in res;
122+
return typeof res === "object" && "ok" in res;
123123
}
124124

125125
export function isApiErrorResponse(res: ApiResponse): res is ApiErrorResponse {
126-
return "err" in res;
126+
return typeof res === "object" && "err" in res;
127127
}

0 commit comments

Comments
 (0)