Fixed #22058 -- Refactored handler and created a generic mechanism to deal with server/client errors.