@@ -103,9 +103,10 @@ C._rpc = function(method, fields, expect, cb) {
103
103
// We have detected a problem, so it's up to us to close the
104
104
// channel
105
105
var expectedName = methodName ( expect ) ;
106
+
106
107
var e = new Error ( fmt ( "Expected %s; got %s" ,
107
108
expectedName , inspect ( f , false ) ) ) ;
108
- self . closeWithError ( fmt ( 'Expected %s; got %s' ,
109
+ self . closeWithError ( f . id , fmt ( 'Expected %s; got %s' ,
109
110
expectedName , methodName ( f . id ) ) ,
110
111
defs . constants . UNEXPECTED_FRAME , e ) ;
111
112
return cb ( e ) ;
@@ -124,7 +125,11 @@ C._rpc = function(method, fields, expect, cb) {
124
125
? fmt ( "Operation failed: %s; %s" ,
125
126
methodName ( method ) , closeMsg ( err ) )
126
127
: fmt ( "Channel closed by server: %s" , closeMsg ( err ) ) ;
127
- return cb ( new Error ( e ) ) ;
128
+ var closeFrameError = new Error ( e ) ;
129
+ closeFrameError . code = err . fields . replyCode ;
130
+ closeFrameError . classId = err . fields . classId ;
131
+ closeFrameError . methodId = err . fields . methodId ;
132
+ return cb ( closeFrameError ) ;
128
133
}
129
134
}
130
135
@@ -210,10 +215,15 @@ C.closeBecause = function(reason, code, k) {
210
215
// If we close because there's been an error, we need to distinguish
211
216
// between what we tell the server (`reason`) and what we report as
212
217
// the cause in the client (`error`).
213
- C . closeWithError = function ( reason , code , error ) {
218
+ C . closeWithError = function ( id , reason , code , error ) {
214
219
var self = this ;
215
220
this . closeBecause ( reason , code , function ( ) {
216
221
error . code = code ;
222
+ // content frames and consumer errors do not provide a method a class/method ID
223
+ if ( id ) {
224
+ error . classId = defs . info ( id ) . classId ;
225
+ error . methodId = defs . info ( id ) . methodId ;
226
+ }
217
227
self . emit ( 'error' , error ) ;
218
228
} ) ;
219
229
} ;
@@ -232,15 +242,15 @@ C.acceptMessageFrame = function(f) {
232
242
}
233
243
catch ( msg ) {
234
244
if ( typeof msg === 'string' ) {
235
- this . closeWithError ( msg , defs . constants . UNEXPECTED_FRAME ,
245
+ this . closeWithError ( f . id , msg , defs . constants . UNEXPECTED_FRAME ,
236
246
new Error ( msg ) ) ;
237
247
}
238
248
else if ( msg instanceof Error ) {
239
- this . closeWithError ( 'Error while processing message' ,
249
+ this . closeWithError ( f . id , 'Error while processing message' ,
240
250
defs . constants . INTERNAL_ERROR , msg ) ;
241
251
}
242
252
else {
243
- this . closeWithError ( 'Internal error while processing message' ,
253
+ this . closeWithError ( f . id , 'Internal error while processing message' ,
244
254
defs . constants . INTERNAL_ERROR ,
245
255
new Error ( msg . toString ( ) ) ) ;
246
256
}
@@ -405,6 +415,8 @@ C.accept = function(f) {
405
415
406
416
var error = new Error ( emsg ) ;
407
417
error . code = f . fields . replyCode ;
418
+ error . classId = f . fields . classId ;
419
+ error . methodId = f . fields . methodId ;
408
420
this . emit ( 'error' , error ) ;
409
421
410
422
var s = stackCapture ( emsg ) ;
@@ -413,7 +425,7 @@ C.accept = function(f) {
413
425
414
426
case defs . BasicFlow :
415
427
// RabbitMQ doesn't send this, it just blocks the TCP socket
416
- return this . closeWithError ( "Flow not implemented" ,
428
+ return this . closeWithError ( f . id , "Flow not implemented" ,
417
429
defs . constants . NOT_IMPLEMENTED ,
418
430
new Error ( 'Flow not implemented' ) ) ;
419
431
0 commit comments