Generally, you can retry idempotent operations once. Please see my MongoDB World talk on how MongoDB drivers implement high availability and failover:
https://www.mongodb.com/presentations/mongodb-drivers-and-high-availability-deep-dive
The talk applies equally to how mongos implements high availability and failover, which is the relevant question in a sharded cluster. Towards the end of the talk I give a reasonable strategy for implementing retries of queries, inserts, updates, and deletes.
For the C Driver specifically, the MONGOC_ERROR_QUERY and MONGOC_ERROR_COMMAND domains imply a server-side rejection of your operation which cannot be successfully retried. However, since you're connecting through mongos, mongos may experience a network disconnect or an unavailable primary when talking to your replica sets—in this case, the error will appear to you as a QUERY / COMMAND error even though it's really a network error between mongos and mongod. I'll wait for someone from the MongoDB server team to chime in with a strategy for distinguishing those errors.
MONGOC_ERROR_COMMAND with a code of 11000 means a duplicate key error, which you can use to determine if the first try of an insert operation succeeded before a network error.
MONGOC_ERROR_CLIENT means a network error. Idempotent operations can be usefully retried one time after a network error. Starting in version 1.2, MONGOC_ERROR_SERVER_SELECTION will also be retryable.