Commit f4f9d0117cc6d023484552a2ae3101569c6c9fce

Authored by Adhidarma Hadiwinoto
1 parent 266323f7c6
Exists in master

cb and transport.send is mutual

Showing 1 changed file with 16 additions and 5 deletions Side-by-side Diff

center/messaging/trx-center.js
... ... @@ -117,22 +117,33 @@ function requestToCore(requestOptions, cb) {
117 117 request(requestOptions, function(err, res, body) {
118 118 if (err || res.statusCode != 200) {
119 119 logger.warn('Error requesting to CORE', {module_name: module_name, method_name: 'requestToCore', requestOptions: requestOptions, err: err});
120   - transport.send(requestOptions.qs.terminal_name, 'INTERNAL ERROR');
121   - if (cb) { cb(null, {msg: 'INTERNAL ERROR'}); }
  120 + if (cb) {
  121 + cb(null, {msg: 'INTERNAL ERROR'});
  122 + }
  123 + else if (transport.send) {
  124 + transport.send(requestOptions.qs.terminal_name, 'INTERNAL ERROR');
  125 + }
122 126 return;
123 127 }
124 128  
125 129 let result = parseCoreMessage(body);
126 130 if (!result || !result.message) {
127   - transport.send(requestOptions.qs.terminal_name, 'INTERNAL ERROR');
128   - if (cb) { cb(null, {msg: 'INTERNAL ERROR'}); }
  131 + if (cb) {
  132 + cb(null, {msg: 'INTERNAL ERROR'});
  133 + }
  134 + else if (transport.send) {
  135 + transport.send(requestOptions.qs.terminal_name, 'INTERNAL ERROR');
  136 + }
129 137 return;
130 138 }
131 139  
132   - transport.send(requestOptions.qs.terminal_name, result.message);
133 140 if (cb) {
134 141 cb(null, result);
135 142 }
  143 + else if (transport.send) {
  144 + transport.send(requestOptions.qs.terminal_name, result.message);
  145 +
  146 + }
136 147 })
137 148 }
138 149