File tree Expand file tree Collapse file tree 2 files changed +581
-93
lines changed Expand file tree Collapse file tree 2 files changed +581
-93
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ class TestingBot {
7575 if ( callbackURL ) {
7676 data . callbackURL = callbackURL ;
7777 }
78- this . request ( {
78+ this . requestJson ( {
7979 method : 'POST' ,
8080 url : '/screenshots' ,
8181 data : data
@@ -364,14 +364,23 @@ class TestingBot {
364364 } ;
365365
366366 if ( req_data . method !== 'GET' ) {
367- requestOptions . form = req_data . data ;
367+ if ( req_data . json ) {
368+ requestOptions . json = true ;
369+ requestOptions . body = req_data . data ;
370+ } else {
371+ requestOptions . form = req_data . data ;
372+ }
368373 }
369374
370375 request ( requestOptions , function ( error , response ) {
371376 let responseBody = null ;
372377 if ( response ) {
373- if ( response . body && typeof ( response . body ) === 'string' ) {
374- response . body = JSON . parse ( response . body ) ;
378+ if ( ! req_data . json && response . body && typeof ( response . body ) === 'string' ) {
379+ try {
380+ response . body = JSON . parse ( response . body ) ;
381+ } catch ( e ) {
382+ // keep body as string if JSON parsing fails
383+ }
375384 }
376385 if ( response . statusCode . toString ( ) . substring ( 0 , 1 ) === '2' ) {
377386 responseBody = response . body ;
@@ -384,6 +393,12 @@ class TestingBot {
384393 }
385394 } ) ;
386395 }
396+
397+ requestJson ( req_data , callback ) {
398+ req_data . json = true ;
399+
400+ return this . request ( req_data , callback ) ;
401+ }
387402}
388403
389404
You can’t perform that action at this time.
0 commit comments