pasika 0.10.3 → 0.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -16,6 +16,10 @@ interface ZodFetchRelayedResponse {
|
|
|
16
16
|
* data the response schema accepted, and a failure back as an `HttpError` carrying
|
|
17
17
|
* the status the upstream reported, the message for a client, and what the upstream
|
|
18
18
|
* answered with. A call that names no response schema gets the response itself.
|
|
19
|
+
*
|
|
20
|
+
* A success that carries no body is the schema's call: one that allows its data to
|
|
21
|
+
* be absent, such as `z.undefined()` for an endpoint answering `204`, accepts it, and
|
|
22
|
+
* one that does not makes it a failure at the upstream's own status.
|
|
19
23
|
*/
|
|
20
24
|
declare function zodFetch<TSchema extends ZodType>(options: ZodFetchOptions<TSchema> & {
|
|
21
25
|
responseSchema: TSchema;
|
|
@@ -33,6 +33,8 @@ async function zodFetch(options) {
|
|
|
33
33
|
}
|
|
34
34
|
const body = await response.text();
|
|
35
35
|
if (body === "") {
|
|
36
|
+
const absent = options.responseSchema.safeParse(void 0);
|
|
37
|
+
if (absent.success) return absent.data;
|
|
36
38
|
throw new HttpError("The upstream answered without a body to decode.", response.status);
|
|
37
39
|
}
|
|
38
40
|
const decoded = JSON.parse(body);
|