@hey-api/openapi-ts 0.87.2 → 0.87.3

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.
@@ -93,7 +93,40 @@ export const createClient = (config: Config = {}): Client => {
93
93
  // fetch must be assigned here, otherwise it would throw the error:
94
94
  // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
95
95
  const _fetch = opts.fetch!;
96
- let response = await _fetch(request);
96
+ let response: Response;
97
+
98
+ try {
99
+ response = await _fetch(request);
100
+ } catch (error) {
101
+ // Handle fetch exceptions (AbortError, network errors, etc.)
102
+ let finalError = error;
103
+
104
+ for (const fn of interceptors.error.fns) {
105
+ if (fn) {
106
+ finalError = (await fn(
107
+ error,
108
+ undefined as any,
109
+ request,
110
+ opts,
111
+ )) as unknown;
112
+ }
113
+ }
114
+
115
+ finalError = finalError || ({} as unknown);
116
+
117
+ if (opts.throwOnError) {
118
+ throw finalError;
119
+ }
120
+
121
+ // Return error response
122
+ return opts.responseStyle === 'data'
123
+ ? undefined
124
+ : {
125
+ error: finalError,
126
+ request,
127
+ response: undefined as any,
128
+ };
129
+ }
97
130
 
98
131
  for (const fn of interceptors.response.fns) {
99
132
  if (fn) {