Fixed timeout that happened if an error occurs

When an error occurred it will just log the error but not return anything. FIxed that by just returning the error.