title: RethinkDB error codes on inserting duplicate primary key
body: <p>What is the best way to handle the error that is thrown when a row with an existing primary key is being inserted.</p>
  
  <p>rethinkdb returns 'Duplicate primary key...' in first_error.</p>
  
  <p>Currently this is how I am handling it:</p>
  
  <pre><code>        if result['errors'] &gt; 0 and 'Duplicate primary key' in result['first_error']:
  </code></pre>
  
  <p>But this seems very brittle, does rethinkdb also return error codes along with error string messages.</p>