Skip to content

Conversation

@1rneh
Copy link
Contributor

@1rneh 1rneh commented Dec 12, 2025

No description provided.

// TODO: Bug 2001078 - ConsoleClient shouldn't use the
// _get function to initiate POST requests
return this._get(path, "POST");
async _post(path, jsonBody) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this is changing the signature, so old callers are passing in undefined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the simplest is just to give this a default and then the other code can stay as it is.

const res = await fetch(url, {
method,
headers,
body: jsonBody === null ? undefined : JSON.stringify(jsonBody),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here you will try to stringify undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just re-checked the behavior of default parameters because I wasn't sure anymore neither:

Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.

So if undefined is passed to _fetch for jsonBody, then it's initialized with the default value null and we won't pass is to JSON.stringify.

const headers = new Headers({});
const accessToken = await this.getAccessToken();
headers.set("Authorization", `Bearer ${accessToken}`);
if (jsonBody !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will trigger even if jsonBody is undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsonBody can't be undefined, see explanation below.

@1rneh 1rneh removed the request for review from fiji-flo December 15, 2025 12:07
@1rneh 1rneh merged commit a766fb8 into enterprise-main Dec 15, 2025
20 of 21 checks passed
@1rneh 1rneh deleted the generic-fetch branch December 15, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants