@@ -4,7 +4,7 @@ import { FetchOptions, HttpClient } from "../net/httpclient";
44import { ODataParser , ODataDefaultParser , ODataBatch } from "./odata" ;
55import { ICachingOptions , CachingParserWrapper , CachingOptions } from "./caching" ;
66import { RuntimeConfig } from "../configuration/pnplibconfig" ;
7- import { ProcessHttpClientResponseException , AlreadyInBatchException } from "../utils/exceptions" ;
7+ import { AlreadyInBatchException } from "../utils/exceptions" ;
88
99export interface QueryableConstructor < T > {
1010 new ( baseUrl : string | Queryable , path ?: string ) : T ;
@@ -271,9 +271,7 @@ export class Queryable {
271271
272272 // we are not part of a batch, so proceed as normal
273273 let client = new HttpClient ( ) ;
274- return client . get ( this . toUrlAndQuery ( ) , getOptions ) . then ( ( response ) => {
275- return this . processHttpClientResponse ( response , parser ) ;
276- } ) ;
274+ return client . get ( this . toUrlAndQuery ( ) , getOptions ) . then ( ( response ) => parser . parse ( response ) ) ;
277275
278276 } else {
279277
@@ -287,9 +285,7 @@ export class Queryable {
287285
288286 // we are not part of a batch, so proceed as normal
289287 let client = new HttpClient ( ) ;
290- return client . post ( this . toUrlAndQuery ( ) , postOptions ) . then ( ( response ) => {
291- return this . processHttpClientResponse ( response , parser ) ;
292- } ) ;
288+ return client . post ( this . toUrlAndQuery ( ) , postOptions ) . then ( ( response ) => parser . parse ( response ) ) ;
293289
294290 } else {
295291 return this . _batch . add ( this . toUrlAndQuery ( ) , "POST" , postOptions , parser ) ;
@@ -302,9 +298,7 @@ export class Queryable {
302298
303299 // we are not part of a batch, so proceed as normal
304300 let client = new HttpClient ( ) ;
305- return client . patch ( this . toUrlAndQuery ( ) , patchOptions ) . then ( ( response ) => {
306- return this . processHttpClientResponse ( response , parser ) ;
307- } ) ;
301+ return client . patch ( this . toUrlAndQuery ( ) , patchOptions ) . then ( ( response ) => parser . parse ( response ) ) ;
308302
309303 } else {
310304 return this . _batch . add ( this . toUrlAndQuery ( ) , "PATCH" , patchOptions , parser ) ;
@@ -317,44 +311,12 @@ export class Queryable {
317311
318312 // we are not part of a batch, so proceed as normal
319313 let client = new HttpClient ( ) ;
320- return client . delete ( this . toUrlAndQuery ( ) , deleteOptions ) . then ( ( response ) => {
321- return this . processHttpClientResponse ( response , parser ) ;
322- } ) ;
314+ return client . delete ( this . toUrlAndQuery ( ) , deleteOptions ) . then ( ( response ) => parser . parse ( response ) ) ;
323315
324316 } else {
325317 return this . _batch . add ( this . toUrlAndQuery ( ) , "DELETE" , deleteOptions , parser ) ;
326318 }
327319 }
328-
329- private processHttpClientResponse < T > ( response : Response , parser : ODataParser < T > ) : Promise < T > {
330-
331- return new Promise < T > ( ( resolve , reject ) => {
332-
333- // 200 = OK (get, delete)
334- // 201 = Created (create)
335- // 204 = No Content (update)
336- if ( response . ok ) {
337-
338- if ( ( response . headers . has ( "Content-Length" ) && parseFloat ( response . headers . get ( "Content-Length" ) ) === 0 )
339- || response . status === 204 ) {
340-
341- // in these cases the server has returned no content, so we create an empty object
342- // this was done because the fetch browser methods throw exceptions with no content
343- return resolve ( < T > { } ) ;
344- }
345-
346- // pipe our parsed content
347- return resolve ( parser . parse ( response ) ) ;
348-
349- } else {
350-
351- // and reject
352- response . json ( ) . then ( json => {
353- return reject ( new ProcessHttpClientResponseException ( response . status , response . statusText , json ) ) ;
354- } ) ;
355- }
356- } ) ;
357- }
358320}
359321
360322/**
0 commit comments