exception handling middleware function added