Generic method to avoid server crash.

Ok. I think @jlipps should review. It looks good to me. :+1: