Refactor getting the error message to its own method.