Skip to content

Commit bd46b55

Browse files
CSHARP-3180: Use server error codes in place of error messages when possible.
1 parent da5c7ab commit bd46b55

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/MongoDB.Driver.Core/Core/Operations/DropCollectionOperation.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* limitations under the License.
1414
*/
1515

16-
using System;
1716
using System.Threading;
1817
using System.Threading.Tasks;
1918
using MongoDB.Bson;
@@ -158,7 +157,9 @@ private WriteCommandOperation<BsonDocument> CreateOperation(ICoreSessionHandle s
158157

159158
private bool ShouldIgnoreException(MongoCommandException ex)
160159
{
161-
return ex.ErrorMessage == "ns not found";
160+
return
161+
ex.Code == (int)ServerErrorCode.NamespaceNotFound ||
162+
ex.ErrorMessage == "ns not found";
162163
}
163164
}
164165
}

src/MongoDB.Driver.Core/Core/Operations/DropIndexOperation.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ public async Task<BsonDocument> ExecuteAsync(IWriteBinding binding, Cancellation
200200

201201
private bool ShouldIgnoreException(MongoCommandException ex)
202202
{
203-
return ex.ErrorMessage != null && ex.ErrorMessage.Contains("ns not found");
203+
return
204+
ex.Code == (int)ServerErrorCode.NamespaceNotFound ||
205+
ex.ErrorMessage != null && ex.ErrorMessage.Contains("ns not found");
204206
}
205207
}
206208
}

src/MongoDB.Driver.Core/ServerErrorCode.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ internal enum ServerErrorCode
3030
Interrupted = 11601,
3131
InterruptedAtShutdown = 11600,
3232
InterruptedDueToReplStateChange = 11602,
33+
MaxTimeMSExpired = 50,
34+
NamespaceNotFound = 26,
3335
NetworkTimeout = 89,
3436
NotMaster = 10107,
3537
NotMasterNoSlaveOk = 13435,
@@ -43,7 +45,6 @@ internal enum ServerErrorCode
4345
StaleShardVersion = 63,
4446
UnknownReplWriteConcern = 79,
4547
UnsatisfiableWriteConcern = 100,
46-
WriteConcernFailed = 64,
47-
MaxTimeMSExpired = 50
48+
WriteConcernFailed = 64
4849
}
4950
}

0 commit comments

Comments
 (0)