Skip to content

Commit 66071a7

Browse files
author
Evgenii Perminov
committed
improve data checks in query/mutation fns
1 parent 428e0ca commit 66071a7

File tree

1 file changed

+8
-2
lines changed
  • packages/openapi-react-query/src

1 file changed

+8
-2
lines changed

packages/openapi-react-query/src/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ export default function createClient<Paths extends {}, Media extends MediaType =
115115
const mth = method.toUpperCase() as Uppercase<typeof method>;
116116
const fn = client[mth] as ClientMethod<Paths, typeof method, Media>;
117117
const { data, error } = await fn(path, { signal, ...(init as any) }); // TODO: find a way to avoid as any
118-
if (error || data === undefined) {
118+
if (error) {
119119
throw error;
120120
}
121+
121122
return data;
122123
};
123124

@@ -141,9 +142,14 @@ export default function createClient<Paths extends {}, Media extends MediaType =
141142
const mth = method.toUpperCase() as Uppercase<typeof method>;
142143
const fn = client[mth] as ClientMethod<Paths, typeof method, Media>;
143144
const { data, error } = await fn(path, init as InitWithUnknowns<typeof init>);
144-
if (error || data === undefined) {
145+
if (error) {
145146
throw error;
146147
}
148+
149+
if (data === undefined) {
150+
throw new Error("Unexpected undefined response");
151+
}
152+
147153
return data;
148154
},
149155
...options,

0 commit comments

Comments
 (0)