created a common error handling method