-
Notifications
You must be signed in to change notification settings - Fork 1
Handle all the errors. #268
Description
Started by @dmsnell in https://github.com/Automattic/notifications-client/issues/170:
There are too many places where the following exist.
function( error, data ) {
if ( error ) { throw error; return; }
}All of these should probably do something or check something.
Known API Error Responses
Comment Endpoint
New comments/replies
-
404 unknown comment - Unknown commentparent comment not found -
404 unknown post - Unknown postparent post not found -
403 unauthorized - User cannot create commentsblog is not public and user is neither a member nor superadmin -
403 unauthorized - Comments on this post are closed -
403 unauthorized - User cannot view post -
403 unauthorized/private_blog - User cannot view postblog not public and noread_postpermission for post -
403 unauthorized/password_protected - User cannot view password protected postpassword exists and noedit_postpermission for post -
403 unauthorized - Comments on drafts are not allowedpost status is neither public nor private -
400 invalid_input - Invalid request inputno input or zero-length input -
403 authorization_required - An active access token must be used to comment. -
400 - Comment cache problem?newly inserted comment doesn't exist after inserting
Like/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".