Fixed error handling in server