Found the answer. It lied in Google's gem google-adwords-api
. The exception raised was of class AdwordsApi::V201309::AdGroupAdService::ApiException
. Besides the message
attribute it has errors
attribute containing the same message in form of a structure. So no need to parse the strange markup syntax.
> pp e.errors
[{:field_path=>"operations[0].operand.ad.headline",
:trigger=>nil,
:error_string=>"PolicyViolationError.POLICY_ERROR",
:api_error_type=>"PolicyViolationError",
:key=>{:policy_name=>"trademark", :violating_text=>"Sony"},
:external_policy_name=>"Trademarked Term",
:external_policy_url=>nil,
:external_policy_description=>
"Due to trademark reasons, we do not allow advertisers to use 'Sony' in their Google AdWords ads. This term may be trademarked either for a certain product or service category and may apply only in certain countries you have targeted.\n\n",
:is_exemptable=>true,
:violating_parts=>[{:index=>0, :length=>4}],
:xsi_type=>"PolicyViolationError"}]
A nice hash from which I can pull policy_name
, violating_text
and other details.