Over the past few years, a number of distributed algorithms have been developed for integrating the measurements acquired by a wireless sensor network. Among them, average consensus algorithms have drawn significant attention due to a number of practical advantages, such as robustness to noise in the measurements, robustness to changes in the network topology and guaranteed convergence to the centralized solution. However, one of the main drawbacks of existing consensus algorithms is their inability to handle outliers in the measurements. This is because they are based on minimizing a Euclidean (L2) loss function, which is known to be sensitive to outliers. In this paper, we propose a distributed optimization framework that can handle outliers in the measurements. The proposed framework generalizes consensus algorithms to robust loss functions that are strictly convex or convex, such as the Huber loss or the L1-loss. This generalization is achieved by posing the robust consensus proble...