Processing mechanism when claiming resources from the server?

In game, when click on button to claim resource, it will call api from server and then if success show claim effect, if not do nothing. But it will delay a bit make user experience not good. In many game I see that the claim action is very smooth without any delay, how they do that? how they handle error if claim fail or any error relate to network?

As you noticed, there is a tradeoff between communication and user experience.

Usually online games need to verify important actions on the server to prevent users to cheat and/or to sync the state between all clients. This is why shooters are very sensitive to delay (“ping”).

But on no-so-important actions, you don’t need to verify all the time, and you can just tell the server that the action happened. This may be your case, is the client who may tell the server that the resource was claimed. When connection is lost, state is returned to the last state verified by the server. This is why some games may move your player to the position it had 1-2 seconds before.

As a final note, if your server is close enough to the client, the communication delay may not be as big as you think. 100ms may be perceived as instant, specially if you use animations wisely to. For example, the resource falling to the floor.