@@ -23,32 +23,41 @@ var Client = function (url, username, password) {
2323 * Render report in temore server and return response
2424 * @returns object containing header property with response headers and body property with response body
2525 */
26- Client . prototype . render = function ( req , cb ) {
27-
28- var requestOptions = {
29- uri : url . resolve ( this . url , 'api/report' ) ,
30- body : JSON . stringify ( req ) ,
31- strictSSL : false ,
32- encoding : null ,
33- headers : {
26+ Client . prototype . render = function ( req , options , cb ) {
27+
28+ if ( typeof cb == 'undefined' ) {
29+ cb = options ;
30+ options = { }
31+ }
32+
33+
34+ options . uri = options . uri || url . resolve ( this . url , 'api/report' ) ;
35+ options . body = options . body || JSON . stringify ( req ) ;
36+ options . strictSSL = options . strictSSL || false ;
37+ options . encoding = options . encoding || null ;
38+ options . headers = options . headers || {
3439 'Content-Type' : 'application/json'
35- }
36- } ;
40+ } ;
41+
3742
3843 if ( this . username ) {
39- requestOptions . auth = {
44+ options . auth = {
4045 username : this . username ,
4146 password : this . password
4247 }
4348 }
4449
45- var responseStream = request . post ( requestOptions ) ;
50+ var responseStream = request . post ( options ) ;
4651
4752 responseStream . on ( "error" , function ( err ) {
4853 cb ( err ) ;
4954 } ) ;
5055
5156 responseStream . on ( "response" , function ( response ) {
57+ response . on ( "error" , function ( err ) {
58+ cb ( err )
59+ } )
60+
5261 if ( response . statusCode !== 200 ) {
5362 return responseToBuffer ( response , function ( data ) {
5463 try {
0 commit comments