diff --git a/open-api/typescript-sdk/src/index.ts b/open-api/typescript-sdk/src/index.ts index 9a2a4b2ee..7adbca4d7 100644 --- a/open-api/typescript-sdk/src/index.ts +++ b/open-api/typescript-sdk/src/index.ts @@ -29,9 +29,7 @@ export const setApiKey = (apiKey: string) => { }; export const setHeader = (key: string, value: string) => { - if (key.toLowerCase() === 'x-api-key') { - throw new Error('The API key header can only be set using setApiKey().'); - } + assertNoApiKey(key); defaults.headers = defaults.headers || {}; defaults.headers[key] = value; }; @@ -39,13 +37,17 @@ export const setHeader = (key: string, value: string) => { export const setHeaders = (headers: Record) => { defaults.headers = defaults.headers || {}; for (const [key, value] of Object.entries(headers)) { - if (key.toLowerCase() === 'x-api-key') { - throw new Error('The API key header can only be set using setApiKey().'); - } + assertNoApiKey(key); defaults.headers[key] = value; } }; +const assertNoApiKey = (headerKey: string) => { + if (headerKey.toLowerCase() === 'x-api-key') { + throw new Error('The API key header can only be set using setApiKey().'); + } +}; + export const getAssetOriginalPath = (id: string) => `/assets/${id}/original`; export const getAssetThumbnailPath = (id: string) => `/assets/${id}/thumbnail`;