Commit 55014bb9a57153eee9a601d7c3705e3843dcffa9

Authored by Adhidarma Hadiwinoto
1 parent a5de2a87ff
Exists in master

prefixMessageWithSN

Showing 1 changed file with 20 additions and 9 deletions Side-by-side Diff

... ... @@ -127,12 +127,7 @@ function _topupRequest(task, pendingOnConnectError) {
127 127 value['RESPONSECODE'] = '68';
128 128 }
129 129  
130   - if (value['RESPONSECODE'] == '00' && value['SN'] && value['SN'].trim()) {
131   - value['MESSAGE'] = 'SN=' + value['SN'].trim() + '; ' + value['MESSAGE'];
132   - }
133   - else if (value['RESPONSECODE'] == '00' && config.h2h_out.parse_sn == 'YES') {
134   - value['MESSAGE'] = 'SN=' + parseSN(value['MESSAGE']) + '; ' + value['MESSAGE'];
135   - }
  130 + value['MESSAGE'] = prefixMessageWithSN(value);
136 131  
137 132 callbackReport(
138 133 task.requestId, value['RESPONSECODE'], value['MESSAGE'], null, JSON.stringify({methodName: methodName, response: value})
... ... @@ -140,6 +135,24 @@ function _topupRequest(task, pendingOnConnectError) {
140 135 });
141 136 }
142 137  
  138 +function prefixMessageWithSN(data) {
  139 +
  140 + if (data['RESPONSECODE'] != '00') {
  141 + return data['MESSAGE'];
  142 + }
  143 +
  144 + if (data['MESSAGE'].search(/^SN=.+;/) == -1) {
  145 + if (data['SN'] && data['SN'].trim()) {
  146 + return 'SN=' + data['SN'].trim() + '; ' + data['MESSAGE'];
  147 + }
  148 + else if (config.h2h_out.parse_sn == 'YES') {
  149 + return = 'SN=' + parseSN(data['MESSAGE']) + '; ' + data['MESSAGE'];
  150 + }
  151 + }
  152 +
  153 + return data['MESSAGE'];
  154 +}
  155 +
143 156 function createServer() {
144 157  
145 158 logger.info('Creating XML-RPC server on port ' + config.h2h_out.listen_port);
... ... @@ -166,9 +179,7 @@ function createServer() {
166 179 value['RESPONSECODE'] = '68';
167 180 }
168 181  
169   - if (value['RESPONSECODE'] == '00' && config.h2h_out.parse_sn == 'YES') {
170   - value['MESSAGE'] = 'SN=' + parseSN(value['MESSAGE']) + '; ' + value['MESSAGE'];
171   - }
  182 + value['MESSAGE'] = prefixMessageWithSN(value);
172 183  
173 184 callbackReport(
174 185 value['REQUESTID'], value['RESPONSECODE'], value['MESSAGE'], null, JSON.stringify({methodName: 'topUpReport', msg: value})