Skip to content

Commit 5f98b56

Browse files
refactor: derive the request url in a standalone private function
Co-authored-by: William Bergamin <[email protected]>
1 parent 5693e04 commit 5f98b56

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

packages/web-api/src/WebClient.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,7 @@ export class WebClient extends Methods {
646646
// TODO: better input types - remove any
647647
const task = () =>
648648
this.requestQueue.add(async () => {
649-
const requestURL =
650-
url.startsWith('https' || 'http') && this.allowAbsoluteUrls ? url : `${this.axios.getUri() + url}`;
649+
const requestURL = this.deriveRequestUrl(url);
651650

652651
try {
653652
// biome-ignore lint/suspicious/noExplicitAny: TODO: type this
@@ -740,6 +739,17 @@ export class WebClient extends Methods {
740739
return pRetry(task, this.retryConfig) as Promise<AxiosResponse<any, any>>;
741740
}
742741

742+
/**
743+
* Get the complete request URL for the provided URL.
744+
* @param url - The resource to POST to. Either a Slack API method or absolute URL.
745+
*/
746+
private deriveRequestUrl(url: string): string {
747+
if (url.startsWith('https' || 'http') && this.allowAbsoluteUrls) {
748+
return url;
749+
}
750+
return `${this.axios.getUri() + url}`;
751+
}
752+
743753
/**
744754
* Transforms options (a simple key-value object) into an acceptable value for a body. This can be either
745755
* a string, used when posting with a content-type of url-encoded. Or, it can be a readable stream, used

0 commit comments

Comments
 (0)