Fixed #22058 -- Refactored the code for handlers.

Created two new Exception types to handle all http errors.

Maintained backward compatibility by allowing to explicitly define custom handlers and keeping intact the earlier Exceptions.