Catching exceptions and returning proper response