Skip to content

Fix returns#3

Open
Fi1osof wants to merge 1 commit intoshrimpy-dev:masterfrom
Fi1osof:fix_returns
Open

Fix returns#3
Fi1osof wants to merge 1 commit intoshrimpy-dev:masterfrom
Fi1osof:fix_returns

Conversation

@Fi1osof
Copy link

@Fi1osof Fi1osof commented Sep 3, 2019

Note: async functions should return pure call, not await (for .catch()).

@Fi1osof
Copy link
Author

Fi1osof commented Sep 3, 2019

Related to #1

@shrimpy-dev
Copy link
Owner

What is the purpose of this PR? You mention it's "for .catch()", but these methods already propagate errors via "await"

@Fi1osof
Copy link
Author

Fi1osof commented Sep 14, 2019

@shrimpy-dev so you should return return await this._callEndpoint<any>(endpoint, 'POST', null, true); instead await this._callEndpoint<any>(endpoint, 'POST', null, true);

await this._callEndpoint<any>(endpoint, 'POST', null, true); does not return anything.

here you do return, but here not.

@shrimpy-dev
Copy link
Owner

Right, we aren't always expecting data. Using your examples, you expect a list of strings back from getIpWhitelistAddresses, but just want to know if the operation was successful for deleteAccount. Because the operation not throwing (i.e. .then() vs .catch()) is enough to determine success, the {"success": true} object doesn't need to be returned to the caller.

Now that you mention it, I see a number of places where we should replace return await with simply await.

@Fi1osof
Copy link
Author

Fi1osof commented Sep 15, 2019

Now that you mention it, I see a number of places where we should replace return await with simply await.

@shrimpy-dev, not "replace return await with simply await.", need replace "simply await" with "return ..." or "return await ...".

See your official API documentation, for example https://developers.shrimpy.io/docs/#naming-a-user
Response: {
"success": true
}

And see code:

public async setUserName(userId: string, name: string): Promise<void> {
const endpoint = `users/${userId}/name`;
const parameters: { [key: string]: any } = {
name: name
};
await this._callEndpoint<any>(endpoint, 'POST', parameters, true);
}

This code does not responsing { "success": true }, it's responsing nothing.

@shrimpy-dev
Copy link
Owner

Right, the docs cover the request/response data. Just because { "success": true }, is sent from the server, doesn't mean it needs to be sent to the caller of the client method (i.e. client.setUserName).

In the docs you linked, you can see the expected usage is await client.setUserName(...), not result = await client.setUserName(...). The same is true in this library's README.md file.

Is there a reason that you want the { "success": true } object to be returned from the client call? What do you plan on doing with it?

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.

2 participants