Skip to content

Commit

Permalink
fix: Fix retry request missing FormData params
Browse files Browse the repository at this point in the history
  • Loading branch information
trandaison committed Apr 2, 2024
1 parent 6828769 commit 794ee8a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/runtime/services/HttpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ export default class HttpService {

try {
const { token } = await this.$auth.refreshTokens();
// Stringify and parse to remove the callback functions (e.g. onResponse, onRequest, etc.)
const opts = JSON.parse(JSON.stringify(options));
const opts = this.cloneOptions(options);
opts.headers = opts.headers || {};
opts.headers[headerName] = `${type} ${token}`;
(opts.headers as any)[headerName] = `${type} ${token}`;
await this.$fetch(request, {
...opts,
auth: false,
retry: false,
onResponse(ctx) {
Object.assign(context, ctx);
},
Expand Down Expand Up @@ -153,4 +153,16 @@ export default class HttpService {
});
return this.nuxtApp.runWithContext(() => navigateTo(loginPath));
}

private cloneOptions<T>(options: T) {
return (Object.keys(options as object) as (keyof T)[]).reduce(
(opts, key) => {
const value = options[key];
if (!value || typeof value === "function") return opts;

return { ...opts, [key]: value };
},
{} as T
);
}
}

0 comments on commit 794ee8a

Please sign in to comment.