AJAX Logout – How to Handle Server Error During AJAX Logout

ajaxloggingui

I need to write a handler for server error during user logout. What is a common practice?

ajax.post({
    url: '/auth/logout'
}).done(function (response) {
    switch (response.statusCode) {
        case 200:
        {
            //update UI related to userinformation
        }
        case 500:
        {
            //what should I do here?
        }
    }
})

Note: The ajax function is reimplementation of $.ajax() with the exception that it always calls done callback (custom promise object is always resolved and never rejected)

UPDATE:
On server I destroy session and delete auto login cookie if it's present. Is it a sensible approach (if server error is received) to delete cookies related to session name and auto login on client using javascript (presuming that I know their names)?

Best Answer

Fundamentally you should do the same thing you did for sucess -- let the user know about it.

Note that this is specific to the front end, because the front end session continues. The back end should return sucess, even if it doesn't have a valid session to close out. Only if it truly is, for some strange reason, going to maintain the session, should it return failure. In which case it is vital that your front end let the user know about it.