这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/six-beds-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

**client-fetch**: intercept AbortError
35 changes: 34 additions & 1 deletion examples/openapi-ts-fastify/src/client/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => {
// fetch must be assigned here, otherwise it would throw the error:
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
const _fetch = opts.fetch!;
let response = await _fetch(request);
let response: Response;

try {
response = await _fetch(request);
} catch (error) {
// Handle fetch exceptions (AbortError, network errors, etc.)
let finalError = error;

for (const fn of interceptors.error.fns) {
if (fn) {
finalError = (await fn(
error,
undefined as any,
request,
opts,
)) as unknown;
}
}

finalError = finalError || ({} as unknown);

if (opts.throwOnError) {
throw finalError;
}

// Return error response
return opts.responseStyle === 'data'
? undefined
: {
error: finalError,
request,
response: undefined as any,
};
}

for (const fn of interceptors.response.fns) {
if (fn) {
Expand Down
35 changes: 34 additions & 1 deletion examples/openapi-ts-fetch/src/client/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => {
// fetch must be assigned here, otherwise it would throw the error:
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
const _fetch = opts.fetch!;
let response = await _fetch(request);
let response: Response;

try {
response = await _fetch(request);
} catch (error) {
// Handle fetch exceptions (AbortError, network errors, etc.)
let finalError = error;

for (const fn of interceptors.error.fns) {
if (fn) {
finalError = (await fn(
error,
undefined as any,
request,
opts,
)) as unknown;
}
}

finalError = finalError || ({} as unknown);

if (opts.throwOnError) {
throw finalError;
}

// Return error response
return opts.responseStyle === 'data'
? undefined
: {
error: finalError,
request,
response: undefined as any,
};
}

for (const fn of interceptors.response.fns) {
if (fn) {
Expand Down
35 changes: 34 additions & 1 deletion examples/openapi-ts-openai/src/client/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => {
// fetch must be assigned here, otherwise it would throw the error:
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
const _fetch = opts.fetch!;
let response = await _fetch(request);
let response: Response;

try {
response = await _fetch(request);
} catch (error) {
// Handle fetch exceptions (AbortError, network errors, etc.)
let finalError = error;

for (const fn of interceptors.error.fns) {
if (fn) {
finalError = (await fn(
error,
undefined as any,
request,
opts,
)) as unknown;
}
}

finalError = finalError || ({} as unknown);

if (opts.throwOnError) {
throw finalError;
}

// Return error response
return opts.responseStyle === 'data'
? undefined
: {
error: finalError,
request,
response: undefined as any,
};
}

for (const fn of interceptors.response.fns) {
if (fn) {
Expand Down
30 changes: 29 additions & 1 deletion examples/openapi-ts-pinia-colada/src/client/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,35 @@ export const createClient = (config: Config = {}): Client => {
// fetch must be assigned here, otherwise it would throw the error:
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
const _fetch = opts.fetch!
let response = await _fetch(request)
let response: Response

try {
response = await _fetch(request)
} catch (error) {
// Handle fetch exceptions (AbortError, network errors, etc.)
let finalError = error

for (const fn of interceptors.error.fns) {
if (fn) {
finalError = (await fn(error, undefined as any, request, opts)) as unknown
}
}

finalError = finalError || ({} as unknown)

if (opts.throwOnError) {
throw finalError
}

// Return error response
return opts.responseStyle === 'data'
? undefined
: {
error: finalError,
request,
response: undefined as any
}
}

for (const fn of interceptors.response.fns) {
if (fn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => {
// fetch must be assigned here, otherwise it would throw the error:
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
const _fetch = opts.fetch!;
let response = await _fetch(request);
let response: Response;

try {
response = await _fetch(request);
} catch (error) {
// Handle fetch exceptions (AbortError, network errors, etc.)
let finalError = error;

for (const fn of interceptors.error.fns) {
if (fn) {
finalError = (await fn(
error,
undefined as any,
request,
opts,
)) as unknown;
}
}

finalError = finalError || ({} as unknown);

if (opts.throwOnError) {
throw finalError;
}

// Return error response
return opts.responseStyle === 'data'
? undefined
: {
error: finalError,
request,
response: undefined as any,
};
}

for (const fn of interceptors.response.fns) {
if (fn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => {
// fetch must be assigned here, otherwise it would throw the error:
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
const _fetch = opts.fetch!;
let response = await _fetch(request);
let response: Response;

try {
response = await _fetch(request);
} catch (error) {
// Handle fetch exceptions (AbortError, network errors, etc.)
let finalError = error;

for (const fn of interceptors.error.fns) {
if (fn) {
finalError = (await fn(
error,
undefined as any,
request,
opts,
)) as unknown;
}
}

finalError = finalError || ({} as unknown);

if (opts.throwOnError) {
throw finalError;
}

// Return error response
return opts.responseStyle === 'data'
? undefined
: {
error: finalError,
request,
response: undefined as any,
};
}

for (const fn of interceptors.response.fns) {
if (fn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,35 @@ export const createClient = (config: Config = {}): Client => {
// fetch must be assigned here, otherwise it would throw the error:
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
const _fetch = opts.fetch!
let response = await _fetch(request)
let response: Response

try {
response = await _fetch(request)
} catch (error) {
// Handle fetch exceptions (AbortError, network errors, etc.)
let finalError = error

for (const fn of interceptors.error.fns) {
if (fn) {
finalError = (await fn(error, undefined as any, request, opts)) as unknown
}
}

finalError = finalError || ({} as unknown)

if (opts.throwOnError) {
throw finalError
}

// Return error response
return opts.responseStyle === 'data'
? undefined
: {
error: finalError,
request,
response: undefined as any
}
}

for (const fn of interceptors.response.fns) {
if (fn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => {
// fetch must be assigned here, otherwise it would throw the error:
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
const _fetch = opts.fetch!;
let response = await _fetch(request);
let response: Response;

try {
response = await _fetch(request);
} catch (error) {
// Handle fetch exceptions (AbortError, network errors, etc.)
let finalError = error;

for (const fn of interceptors.error.fns) {
if (fn) {
finalError = (await fn(
error,
undefined as any,
request,
opts,
)) as unknown;
}
}

finalError = finalError || ({} as unknown);

if (opts.throwOnError) {
throw finalError;
}

// Return error response
return opts.responseStyle === 'data'
? undefined
: {
error: finalError,
request,
response: undefined as any,
};
}

for (const fn of interceptors.response.fns) {
if (fn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,40 @@ export const createClient = (config: Config = {}): Client => {
// fetch must be assigned here, otherwise it would throw the error:
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
const _fetch = opts.fetch!;
let response = await _fetch(request);
let response: Response;

try {
response = await _fetch(request);
} catch (error) {
// Handle fetch exceptions (AbortError, network errors, etc.)
let finalError = error;

for (const fn of interceptors.error.fns) {
if (fn) {
finalError = (await fn(
error,
undefined as any,
request,
opts,
)) as unknown;
}
}

finalError = finalError || ({} as unknown);

if (opts.throwOnError) {
throw finalError;
}

// Return error response
return opts.responseStyle === 'data'
? undefined
: {
error: finalError,
request,
response: undefined as any,
};
}

for (const fn of interceptors.response.fns) {
if (fn) {
Expand Down
Loading
Loading