Fixed #22058 -- Refactored handlers and added a general mechanism to deal with client and server errors.