handle writeStream errors
stricter checking of request type