import { RequestInit , Interceptor , RetryConfiguration } from './interfaces' ; import { RetryInterceptor } from './retry-interceptor' ; /**
 * A class for configuring HttpClients.
 */ export class HttpClientConfiguration { /**
     * The base URL to be prepended to each Request's url before sending.
     */ baseUrl : string = '' ; /**
     * Default values to apply to init objects when creating Requests. Note that
     * defaults cannot be applied when Request objects are manually created because
     * Request provides its own defaults and discards the original init object.
     * See also https://developer.mozilla.org/en-US/docs/Web/API/Request/Request
     */ defaults : RequestInit = { } ; /**
     * Interceptors to be added to the HttpClient.
     */ interceptors : Interceptor [ ] = [ ] ; param baseUrl returns chainable withBaseUrl ( baseUrl ) { this . baseUrl = baseUrl ; return this ; } param defaults returns chainable withDefaults ( defaults ) { this . defaults = defaults ; return this ; } param interceptor returns chainable withInterceptor ( interceptor ) { this . interceptors . push ( interceptor ) ; return this ; } returns chainable useStandardConfiguration ( ) { let standardConfig = { credentials : 'same-origin' } ; Object . assign ( this . defaults , standardConfig , this . defaults ) ; return this . rejectErrorResponses ( ) ; } returns chainable rejectErrorResponses ( ) { return this . withInterceptor ( { response : rejectOnError } ) ; } withRetry ( config ? ) { const interceptor = new RetryInterceptor ( config ) ; return this . withInterceptor ( interceptor ) ; } } function rejectOnError ( response ) { if ( ! response . ok ) { throw response ; } return response ; }