@@ -140,14 +140,27 @@ function parseBatchResponse(response, parseParams, requestNumber) {
140140 var responseData = batchResponse . substring ( batchResponse . indexOf ( "{" ) , batchResponse . lastIndexOf ( "}" ) + 1 ) ;
141141
142142 if ( ! responseData ) {
143- var entityUrl = / O D a t a - E n t i t y I d .+ / i. exec ( batchResponse ) ;
143+ if ( / C o n t e n t - T y p e : t e x t \/ p l a i n / i. test ( batchResponse ) ) {
144+ var plainContentReg = / \w + $ / gi. exec ( batchResponse . trim ( ) ) ;
145+ var plainContent = plainContentReg && plainContentReg . length ? plainContentReg [ 0 ] : undefined ;
144146
145- if ( entityUrl && entityUrl . length ) {
146- result . push ( / ( [ 0 - 9 A - F ] { 8 } [ - ] ? ( [ 0 - 9 A - F ] { 4 } [ - ] ? ) { 3 } [ 0 - 9 A - F ] { 12 } ) \) $ / i. exec ( entityUrl [ 0 ] ) [ 1 ] ) ;
147- }
148- else if ( parseParams [ i ] . hasOwnProperty ( 'valueIfEmpty' ) ) {
149- result . push ( parseParams [ i ] . valueIfEmpty ) ;
147+ //check if a plain content is a number or not
148+ result . push ( isNaN ( plainContent ) ? plainContent : parseInt ( plainContent ) ) ;
150149 }
150+ else
151+ if ( parseParams [ requestNumber ] . hasOwnProperty ( 'valueIfEmpty' ) ) {
152+ result . push ( parseParams [ requestNumber ] . valueIfEmpty ) ;
153+ }
154+ else {
155+ var entityUrl = / O D a t a - E n t i t y I d .+ / i. exec ( batchResponse ) ;
156+
157+ if ( entityUrl && entityUrl . length ) {
158+ result . push ( / ( [ 0 - 9 A - F ] { 8 } [ - ] ? ( [ 0 - 9 A - F ] { 4 } [ - ] ? ) { 3 } [ 0 - 9 A - F ] { 12 } ) \) $ / i. exec ( entityUrl [ 0 ] ) [ 1 ] ) ;
159+ }
160+ else {
161+ result . push ( undefined ) ;
162+ }
163+ }
151164 }
152165 else {
153166 result . push ( parseData ( JSON . parse ( responseData , dateReviver ) , parseParams [ requestNumber ] ) ) ;
@@ -182,16 +195,17 @@ module.exports = function parseResponse(response, responseHeaders, parseParams)
182195 }
183196 }
184197 else {
185- if ( responseHeaders [ 'OData-EntityId' ] || responseHeaders [ 'odata-entityid' ] ) {
186- var entityUrl = responseHeaders [ 'OData-EntityId' ]
187- ? responseHeaders [ 'OData-EntityId' ]
188- : responseHeaders [ 'odata-entityid' ] ;
189-
190- parseResult = / ( [ 0 - 9 A - F ] { 8 } [ - ] ? ( [ 0 - 9 A - F ] { 4 } [ - ] ? ) { 3 } [ 0 - 9 A - F ] { 12 } ) \) $ / i. exec ( entityUrl ) [ 1 ] ;
191- }
192- else if ( parseParams . length && parseParams [ 0 ] . hasOwnProperty ( 'valueIfEmpty' ) ) {
198+ if ( parseParams . length && parseParams [ 0 ] . hasOwnProperty ( 'valueIfEmpty' ) ) {
193199 parseResult = parseParams [ 0 ] . valueIfEmpty ;
194200 }
201+ else
202+ if ( responseHeaders [ 'OData-EntityId' ] || responseHeaders [ 'odata-entityid' ] ) {
203+ var entityUrl = responseHeaders [ 'OData-EntityId' ]
204+ ? responseHeaders [ 'OData-EntityId' ]
205+ : responseHeaders [ 'odata-entityid' ] ;
206+
207+ parseResult = / ( [ 0 - 9 A - F ] { 8 } [ - ] ? ( [ 0 - 9 A - F ] { 4 } [ - ] ? ) { 3 } [ 0 - 9 A - F ] { 12 } ) \) $ / i. exec ( entityUrl ) [ 1 ] ;
208+ }
195209 }
196210
197211 return parseResult ;
0 commit comments