Skip to content

Commit c2dd146

Browse files
committed
fix: addHeaders default param and mergeAbortSignals order in RequestConfigBuilder (#615)
- Add default empty object parameter to addHeaders() so calling with undefined no longer throws TypeError from Object.keys(undefined) - Reorder mergeAbortSignals to check primarySignal.aborted before allocating AbortController, preventing unnecessary controller creation
1 parent c9fab68 commit c2dd146

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/api/providers/config-builder/request-config-builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class RequestConfigBuilder<TOptions extends Record<string, any> = Record<
3838
* @param headers - Key-value pairs of header names and values
3939
* @returns this for chainable calls
4040
*/
41-
addHeaders(headers: Record<string, string>): this {
41+
addHeaders(headers: Record<string, string> = {}): this {
4242
if (Object.keys(headers).length === 0) {
4343
return this
4444
}
@@ -121,12 +121,12 @@ export class RequestConfigBuilder<TOptions extends Record<string, any> = Record<
121121
return primarySignal
122122
}
123123

124-
const controller = new AbortController()
125-
126124
if (primarySignal.aborted) {
127125
return primarySignal
128126
}
129127

128+
const controller = new AbortController()
129+
130130
primarySignal.addEventListener("abort", () => controller.abort(), { once: true })
131131
secondarySignal.addEventListener("abort", () => controller.abort(), { once: true })
132132

0 commit comments

Comments
 (0)