11var http = require ( 'http' ) ;
22var url = require ( 'url' ) ;
3- var qs = require ( 'qs' ) ;
43
54var config = require ( '../config' ) ;
65
@@ -31,7 +30,8 @@ TraceReporter.prototype.send = function (data, callback) {
3130 path : opts . path ,
3231 method : 'POST' ,
3332 headers : {
34- 'Authorization' : 'Bearer ' + this . apiKey
33+ 'Authorization' : 'Bearer ' + this . apiKey ,
34+ 'Content-Type' : 'application/json'
3535 }
3636 } , function ( ) {
3737 return callback ( null ) ;
@@ -40,7 +40,7 @@ TraceReporter.prototype.send = function (data, callback) {
4040 return callback ( err ) ;
4141 } ) ;
4242
43- req . write ( qs . stringify ( data ) ) ;
43+ req . write ( JSON . stringify ( data ) ) ;
4444 req . end ( ) ;
4545} ;
4646
@@ -55,12 +55,19 @@ TraceReporter.prototype.getService = function(callback) {
5555 path : opts . path ,
5656 method : 'POST' ,
5757 headers : {
58- 'Authorization' : 'Bearer ' + this . apiKey
58+ 'Authorization' : 'Bearer ' + this . apiKey ,
59+ 'Content-Type' : 'application/json'
5960 }
6061 } , function ( res ) {
6162 res . setEncoding ( 'utf8' ) ;
6263 res . on ( 'data' , function ( chunk ) {
63- return callback ( null , JSON . parse ( chunk ) ) ;
64+ var res ;
65+ try {
66+ res = JSON . parse ( chunk ) ;
67+ } catch ( ex ) {
68+ return callback ( ex ) ;
69+ }
70+ return callback ( null , res ) ;
6471 } ) ;
6572 } )
6673 . on ( 'error' , function ( err ) {
@@ -71,7 +78,7 @@ TraceReporter.prototype.getService = function(callback) {
7178 }
7279 } ) ;
7380
74- req . write ( qs . stringify ( {
81+ req . write ( JSON . stringify ( {
7582 name : _this . appName
7683 } ) ) ;
7784 req . end ( ) ;
0 commit comments