@@ -75,9 +75,9 @@ def command(sock, dbname, spec, slave_ok, is_mongos,
75
75
monitoring .publish_command_start (orig , dbname , request_id , address )
76
76
start = datetime .datetime .now ()
77
77
78
- sock .sendall (msg )
79
- response = receive_message (sock , 1 , request_id )
80
78
try :
79
+ sock .sendall (msg )
80
+ response = receive_message (sock , 1 , request_id )
81
81
unpacked = helpers ._unpack_response (
82
82
response , codec_options = codec_options )
83
83
@@ -86,11 +86,15 @@ def command(sock, dbname, spec, slave_ok, is_mongos,
86
86
msg = "command %s on namespace %s failed: %%s" % (
87
87
repr (spec ).replace ("%" , "%%" ), ns )
88
88
helpers ._check_command_response (response_doc , msg , allowable_errors )
89
- except ( NotMasterError , OperationFailure ) as exc :
89
+ except Exception as exc :
90
90
if publish :
91
91
duration = (datetime .datetime .now () - start ) + encoding_duration
92
+ if isinstance (exc , (NotMasterError , OperationFailure )):
93
+ failure = exc .details
94
+ else :
95
+ failure = message ._convert_exception (exc )
92
96
monitoring .publish_command_failure (
93
- duration , exc . details , name , request_id , address )
97
+ duration , failure , name , request_id , address )
94
98
raise
95
99
if publish :
96
100
duration = (datetime .datetime .now () - start ) + encoding_duration
0 commit comments