catch IOError and set content type before setting headers