11// This file is auto-generated by @hey-api/openapi-ts
22
3- import type { HTTPError , Options as KyOptions } from 'ky' ;
4- import ky from 'ky' ;
3+ import type { KyResponse , Options as KyOptions } from 'ky' ;
4+ import ky , { isHTTPError } from 'ky' ;
55
66import { createSseClient } from '../core/serverSentEvents.gen' ;
77import type { HttpMethod } from '../core/types.gen' ;
88import { getValidRequestBody } from '../core/utils.gen' ;
9- import type {
10- Client ,
11- Config ,
12- RequestOptions ,
13- ResolvedRequestOptions ,
14- RetryOptions ,
15- } from './types.gen' ;
9+ import type { Client , Config , RequestOptions , ResolvedRequestOptions } from './types.gen' ;
1610import type { Middleware } from './utils.gen' ;
1711import {
1812 buildUrl ,
@@ -49,6 +43,11 @@ export const createClient = (config: Config = {}): Client => {
4943 ...options ,
5044 headers : mergeHeaders ( _config . headers , options . headers ) ,
5145 ky : options . ky ?? _config . ky ?? ky ,
46+ // deep merge kyOptions to ensure base _config is being respected
47+ kyOptions : {
48+ ..._config . kyOptions ,
49+ ...options . kyOptions ,
50+ } ,
5251 serializedBody : undefined as string | undefined ,
5352 } ;
5453
@@ -130,33 +129,23 @@ export const createClient = (config: Config = {}): Client => {
130129
131130 const kyOptions : KyOptions = {
132131 body : validBody as BodyInit ,
133- cache : opts . cache ,
134- credentials : opts . credentials ,
135- headers : opts . headers ,
136- integrity : opts . integrity ,
137- keepalive : opts . keepalive ,
138- method : opts . method as KyOptions [ 'method' ] ,
139- mode : opts . mode ,
140- redirect : 'follow' ,
141- referrer : opts . referrer ,
142- referrerPolicy : opts . referrerPolicy ,
143- signal : opts . signal ,
132+ ... ( opts . cache !== undefined ? { cache : opts . cache } : { } ) ,
133+ ... ( opts . credentials !== undefined ? { credentials : opts . credentials } : { } ) ,
134+ ... ( opts . headers !== undefined ? { headers : opts . headers } : { } ) ,
135+ ... ( opts . integrity !== undefined ? { integrity : opts . integrity } : { } ) ,
136+ ... ( opts . keepalive !== undefined ? { keepalive : opts . keepalive } : { } ) ,
137+ ... ( opts . method !== undefined ? { method : opts . method } : { } ) ,
138+ ... ( opts . mode !== undefined ? { mode : opts . mode } : { } ) ,
139+ redirect : opts . redirect ?? 'follow' ,
140+ ... ( opts . referrer !== undefined ? { referrer : opts . referrer } : { } ) ,
141+ ... ( opts . referrerPolicy !== undefined ? { referrerPolicy : opts . referrerPolicy } : { } ) ,
142+ ... ( opts . signal !== undefined ? { signal : opts . signal } : { } ) ,
144143 throwHttpErrors : opts . throwOnError ?? false ,
145- timeout : opts . timeout ,
144+ ... ( opts . timeout !== undefined ? { timeout : opts . timeout } : { } ) ,
146145 ...opts . kyOptions ,
146+ retry : opts . retry ?? opts . kyOptions ?. retry ?? 2 ,
147147 } ;
148148
149- if ( opts . retry && typeof opts . retry === 'object' ) {
150- const retryOpts = opts . retry as RetryOptions ;
151- kyOptions . retry = {
152- limit : retryOpts . limit ?? 2 ,
153- methods : retryOpts . methods as Array <
154- 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete' | 'options' | 'trace'
155- > ,
156- statusCodes : retryOpts . statusCodes ,
157- } ;
158- }
159-
160149 let request = new Request ( url , {
161150 body : kyOptions . body as BodyInit ,
162151 headers : kyOptions . headers as HeadersInit ,
@@ -169,14 +158,13 @@ export const createClient = (config: Config = {}): Client => {
169158 }
170159 }
171160
172- let response : Response ;
161+ let response : KyResponse ;
173162
174163 try {
175164 response = await kyInstance ( request , kyOptions ) ;
176165 } catch ( error ) {
177- if ( error && typeof error === 'object' && 'response' in error ) {
178- const httpError = error as HTTPError ;
179- response = httpError . response ;
166+ if ( isHTTPError ( error ) ) {
167+ response = error . response ;
180168
181169 for ( const fn of interceptors . response . fns ) {
182170 if ( fn ) {
0 commit comments