How to handle invalid cert when pinning Android with react native

Had searched around and successfully pinned the cert in Android.

However the app crashes if you provide an invalid key.

Is there a way to handle it more gracefully?

Am using the network_security_config

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
   <domain-config>
       <domain includeSubdomains="true">example.com</domain>
       <pin-set>
           <pin digest="SHA-256">ZC3lTYTDBJQVf1P2V7+fibTqbIsWNR/X7CWNVW+CEEA=</pin>
           <pin digest="SHA-256">GUAL5bejH7czkXcAeJ0vCiRxwMnVBsDlBMBsFtfLF8A=</pin>
       </pin-set>
   </domain-config>
</network-security-config>

example from this post: https://www.netguru.com/blog/3-ways-how-to-implement-certificate-pinning-on-android

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum