Skip to content

Commit 1039cf9

Browse files
committed
fix(clients): build URL after request interceptors + thread finalError through error chain
`client-next`: `beforeRequest()` computed the final URL before any request interceptor ran, so request interceptors that mutated `opts.baseUrl`, `opts.url`, `opts.path`, or `opts.query` had no effect — the pre-interceptor URL was already closed over by the fetch call. Move `buildUrl(opts)` to after the request interceptor loop in both the `request` and `makeSseFn` paths so interceptor mutations are honored. `client-next`, `client-ky`, `client-fetch`: error interceptor chains passed `error` (the raw initial error) into every interceptor invocation instead of `finalError` (the running accumulator). This broke composition: each interceptor saw the original error rather than the previous interceptor's output, so transformations from earlier interceptors were silently discarded. Thread `finalError` through instead, matching how `client-angular` and `client-ofetch` already work. Fixes #3803.
1 parent 6cf6b1a commit 1039cf9

187 files changed

Lines changed: 495 additions & 399 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
**clients**: fix: build URL after request interceptors in `client-next`, and thread `finalError` through error interceptor chains in `client-next`, `client-ky`, and `client-fetch`

packages/openapi-ts-tests/__snapshots__/plugins/@tanstack/meta/client/client.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const createClient = (config: Config = {}): Client => {
103103

104104
for (const fn of interceptors.error.fns) {
105105
if (fn) {
106-
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
106+
finalError = (await fn(finalError, undefined as any, request, opts)) as unknown;
107107
}
108108
}
109109

@@ -223,7 +223,7 @@ export const createClient = (config: Config = {}): Client => {
223223

224224
for (const fn of interceptors.error.fns) {
225225
if (fn) {
226-
finalError = (await fn(error, response, request, opts)) as string;
226+
finalError = (await fn(finalError, response, request, opts)) as string;
227227
}
228228
}
229229

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/client.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const createClient = (config: Config = {}): Client => {
103103

104104
for (const fn of interceptors.error.fns) {
105105
if (fn) {
106-
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
106+
finalError = (await fn(finalError, undefined as any, request, opts)) as unknown;
107107
}
108108
}
109109

@@ -223,7 +223,7 @@ export const createClient = (config: Config = {}): Client => {
223223

224224
for (const fn of interceptors.error.fns) {
225225
if (fn) {
226-
finalError = (await fn(error, response, request, opts)) as string;
226+
finalError = (await fn(finalError, response, request, opts)) as string;
227227
}
228228
}
229229

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/client/client.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const createClient = (config: Config = {}): Client => {
103103

104104
for (const fn of interceptors.error.fns) {
105105
if (fn) {
106-
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
106+
finalError = (await fn(finalError, undefined as any, request, opts)) as unknown;
107107
}
108108
}
109109

@@ -223,7 +223,7 @@ export const createClient = (config: Config = {}): Client => {
223223

224224
for (const fn of interceptors.error.fns) {
225225
if (fn) {
226-
finalError = (await fn(error, response, request, opts)) as string;
226+
finalError = (await fn(finalError, response, request, opts)) as string;
227227
}
228228
}
229229

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const createClient = (config: Config = {}): Client => {
103103

104104
for (const fn of interceptors.error.fns) {
105105
if (fn) {
106-
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
106+
finalError = (await fn(finalError, undefined as any, request, opts)) as unknown;
107107
}
108108
}
109109

@@ -223,7 +223,7 @@ export const createClient = (config: Config = {}): Client => {
223223

224224
for (const fn of interceptors.error.fns) {
225225
if (fn) {
226-
finalError = (await fn(error, response, request, opts)) as string;
226+
finalError = (await fn(finalError, response, request, opts)) as string;
227227
}
228228
}
229229

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const createClient = (config: Config = {}): Client => {
103103

104104
for (const fn of interceptors.error.fns) {
105105
if (fn) {
106-
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
106+
finalError = (await fn(finalError, undefined as any, request, opts)) as unknown;
107107
}
108108
}
109109

@@ -223,7 +223,7 @@ export const createClient = (config: Config = {}): Client => {
223223

224224
for (const fn of interceptors.error.fns) {
225225
if (fn) {
226-
finalError = (await fn(error, response, request, opts)) as string;
226+
finalError = (await fn(finalError, response, request, opts)) as string;
227227
}
228228
}
229229

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/client/client.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const createClient = (config: Config = {}): Client => {
103103

104104
for (const fn of interceptors.error.fns) {
105105
if (fn) {
106-
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
106+
finalError = (await fn(finalError, undefined as any, request, opts)) as unknown;
107107
}
108108
}
109109

@@ -223,7 +223,7 @@ export const createClient = (config: Config = {}): Client => {
223223

224224
for (const fn of interceptors.error.fns) {
225225
if (fn) {
226-
finalError = (await fn(error, response, request, opts)) as string;
226+
finalError = (await fn(finalError, response, request, opts)) as string;
227227
}
228228
}
229229

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/client/client.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const createClient = (config: Config = {}): Client => {
103103

104104
for (const fn of interceptors.error.fns) {
105105
if (fn) {
106-
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
106+
finalError = (await fn(finalError, undefined as any, request, opts)) as unknown;
107107
}
108108
}
109109

@@ -223,7 +223,7 @@ export const createClient = (config: Config = {}): Client => {
223223

224224
for (const fn of interceptors.error.fns) {
225225
if (fn) {
226-
finalError = (await fn(error, response, request, opts)) as string;
226+
finalError = (await fn(finalError, response, request, opts)) as string;
227227
}
228228
}
229229

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/client/client.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const createClient = (config: Config = {}): Client => {
103103

104104
for (const fn of interceptors.error.fns) {
105105
if (fn) {
106-
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
106+
finalError = (await fn(finalError, undefined as any, request, opts)) as unknown;
107107
}
108108
}
109109

@@ -223,7 +223,7 @@ export const createClient = (config: Config = {}): Client => {
223223

224224
for (const fn of interceptors.error.fns) {
225225
if (fn) {
226-
finalError = (await fn(error, response, request, opts)) as string;
226+
finalError = (await fn(finalError, response, request, opts)) as string;
227227
}
228228
}
229229

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/typescript/transforms-read-write-custom-name/client/client.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const createClient = (config: Config = {}): Client => {
103103

104104
for (const fn of interceptors.error.fns) {
105105
if (fn) {
106-
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
106+
finalError = (await fn(finalError, undefined as any, request, opts)) as unknown;
107107
}
108108
}
109109

@@ -223,7 +223,7 @@ export const createClient = (config: Config = {}): Client => {
223223

224224
for (const fn of interceptors.error.fns) {
225225
if (fn) {
226-
finalError = (await fn(error, response, request, opts)) as string;
226+
finalError = (await fn(finalError, response, request, opts)) as string;
227227
}
228228
}
229229

0 commit comments

Comments
 (0)