@@ -61,10 +61,14 @@ function setKoaResponse(ctx, response) {
61
61
}
62
62
}
63
63
64
- // Save response body of the primary route
65
- ctx . resBody = Buffer . isBuffer ( response . body )
66
- ? response . body . toString ( )
67
- : response . body
64
+ // Save response details of the primary route
65
+ ctx . resDetails = {
66
+ status : response . status ,
67
+ headers : response . headers ,
68
+ body : Buffer . isBuffer ( response . body )
69
+ ? response . body . toString ( )
70
+ : response . body
71
+ }
68
72
69
73
for ( const key in response . headers ) {
70
74
const value = response . headers [ key ]
@@ -299,6 +303,10 @@ function sendRequestToRoutes(ctx, routes, next) {
299
303
300
304
if ( route . primary ) {
301
305
ctx . primaryRoute = route
306
+
307
+ // Save request body of the primary route
308
+ ctx . reqBody = Buffer . isBuffer ( ctx . body ) ? ctx . body . toString ( ) : ctx . body
309
+
302
310
promise = sendRequest ( ctx , route , options )
303
311
. then ( response => {
304
312
logger . info ( `executing primary route : ${ route . name } ` )
@@ -493,11 +501,6 @@ function sendRequest(ctx, route, options) {
493
501
}
494
502
}
495
503
496
- if ( route . primary ) {
497
- // Save request body of the primary route
498
- ctx . reqBody = Buffer . isBuffer ( ctx . body ) ? ctx . body . toString ( ) : ctx . body
499
- }
500
-
501
504
if ( response instanceof Error ) {
502
505
orchestration . error = {
503
506
message : response . message ,
@@ -668,8 +671,8 @@ function sendKafkaRequest(ctx, route) {
668
671
path : ctx . request . url ,
669
672
pattern : channel . urlPattern ,
670
673
headers : ctx . request . headers ,
671
- requestBody : ctx . reqBody ?? '' ,
672
- responseBody : ctx . resBody ?? ''
674
+ body : ctx . reqBody ?? '' ,
675
+ response : ctx . resDetails ?? { }
673
676
}
674
677
675
678
return producer
0 commit comments