title: how to catch firestore permission denied exception when the user doesn't have enough permissions to write to the database?
body: <p>When I try to write to database with a user account that doesn't have write permission I get this exception as expected</p>
  <blockquote>
  <p>Exception has occurred.
  PlatformException (PlatformException(firebase_firestore, com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions., {code: permission-denied, message: The caller does not have permission to execute the specified operation.}))</p>
  </blockquote>
  <p>But I am unable to catch it.</p>
  <p>Calling this Method causes the exception</p>
  <pre><code>Future&lt;void&gt; addRecord(Product product) async {
      try {
        await FirebaseFirestore.instance
            .collection(&quot;products&quot;)
            .doc()
            .set(product.toMap())
            .catchError((err) {
          print(&quot;error is&quot; + err.toString());
        });
      } on PlatformException catch (e) {
        print(&quot;eee&quot; + e.toString());
      }
    }
  </code></pre>
  <p>This exception is I believe caught as in the console I am getting this message:</p>
  <blockquote>
  <p>eee[cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.</p>
  </blockquote>
  <p>But there is one more message in the console</p>
  <blockquote>
  <p>W/Firestore(12930): (21.4.3) [Firestore]: Write failed at products/SPeUO9260uCoIfpDsSag: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}</p>
  </blockquote>