Handling autentication errors, connection timeout errors, other unknown errors. Re formatted the code according to Apache standards