Robust inference for generalized linear models with application to logistic regression