In many places we update the UI to reflect changes we are requesting from the server, such as when liking a comment. The local client sets the like status and waits for a response from the API request to reload the affected note(s). When we have API requests that never succeed, the new note data is never called and thus the UI reflects the wrong state for those values. In these cases, we should undo the optimistic changes and reset the UI.
Retry attempts
Errors that are denials, such as unauthorized should never be resent. Sending the API request a second or third time will normally result in the same error. Instead, we should stop trying and indicate to the user that something happened, such as a message saying "Could not complete: comment not found".
Started by @dmsnell in https://github.com/Automattic/notifications-client/issues/170:
There are too many places where the following exist.
All of these should probably do something or check something.
Known API Error Responses
Comment Endpoint
New comments/replies
404 unknown comment - Unknown comment
parent comment not found404 unknown post - Unknown post
parent post not found403 unauthorized - User cannot create comments
blog is not public and user is neither a member nor superadmin403 unauthorized - Comments on this post are closed
403 unauthorized - User cannot view post
403 unauthorized/private_blog - User cannot view post
blog not public and noread_post
permission for post403 unauthorized/password_protected - User cannot view password protected post
password exists and noedit_post
permission for post403 unauthorized - Comments on drafts are not allowed
post status is neither public nor private400 invalid_input - Invalid request input
no input or zero-length input403 authorization_required - An active access token must be used to comment.
400 - Comment cache problem?
newly inserted comment doesn't exist after insertingLike/unlike
Approve/unapprove
Spam
Trash
Proper Behavior
Optimistic updating
In many places we update the UI to reflect changes we are requesting from the server, such as when liking a comment. The local client sets the like status and waits for a response from the API request to reload the affected note(s). When we have API requests that never succeed, the new note data is never called and thus the UI reflects the wrong state for those values. In these cases, we should undo the optimistic changes and reset the UI.
Retry attempts
Errors that are denials, such as
unauthorized
should never be resent. Sending the API request a second or third time will normally result in the same error. Instead, we should stop trying and indicate to the user that something happened, such as a message saying "Could not complete: comment not found".