Skip to content

Commit

Permalink
fix: store client instance in a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlubos committed Dec 12, 2024
1 parent 1f39b73 commit cbf4e84
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-chicken-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/client-axios': patch
---

fix: assign axios to variable before sending requests
5 changes: 5 additions & 0 deletions .changeset/gorgeous-dryers-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/client-fetch': patch
---

fix: assign fetch to variable before sending requests
4 changes: 3 additions & 1 deletion packages/client-axios/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export const createClient = (config: Config): Client => {
const url = buildUrl(opts);

try {
const response = await opts.axios({
// assign Axios here for consistency with fetch
const _axios = opts.axios;
const response = await _axios({
...opts,
data: opts.body,
headers: opts.headers as RawAxiosRequestHeaders,
Expand Down
5 changes: 4 additions & 1 deletion packages/client-fetch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export const createClient = (config: Config = {}): Client => {
request = await fn(request, opts);
}

let response = await opts.fetch(request);
// 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);

for (const fn of interceptors.response._fns) {
response = await fn(response, request, opts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export const createClient = (config: Config): Client => {
const url = buildUrl(opts);

try {
const response = await opts.axios({
// assign Axios here for consistency with fetch
const _axios = opts.axios;
const response = await _axios({
...opts,
data: opts.body,
headers: opts.headers as RawAxiosRequestHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export const createClient = (config: Config): Client => {
const url = buildUrl(opts);

try {
const response = await opts.axios({
// assign Axios here for consistency with fetch
const _axios = opts.axios;
const response = await _axios({
...opts,
data: opts.body,
headers: opts.headers as RawAxiosRequestHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export const createClient = (config: Config = {}): Client => {
request = await fn(request, opts);
}

let response = await opts.fetch(request);
// 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);

for (const fn of interceptors.response._fns) {
response = await fn(response, request, opts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export const createClient = (config: Config = {}): Client => {
request = await fn(request, opts);
}

let response = await opts.fetch(request);
// 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);

for (const fn of interceptors.response._fns) {
response = await fn(response, request, opts);
Expand Down

0 comments on commit cbf4e84

Please sign in to comment.