Fixed #22058 -- Refactored handlers and added a general mechanism to deal with client and server errors.
Fixed #21668 -- Better error messages for catched excpetions.