Options
All
  • Public
  • Public/Protected
  • All
Menu

External module chrome/http

Fetch with optional authentication and exponential back-off

Index

Variables

Const AUTH_HEADER

AUTH_HEADER: "Authorization" = "Authorization"

Authorization header

Const BEARER

BEARER: "Bearer" = "Bearer"

Bearer parameter for authorized call

Const DELAY

DELAY: 1000 = 1000

Delay multiplier for exponential back-off

Const MAX_RETRIES

MAX_RETRIES: 4 = 4

Max retries on 500 errors

Functions

doFetch

  • doFetch(url: string, opts: RequestInit, conf: IConfig, attempt: number): Promise<any>
  • Perform fetch, optionally using authorization and exponential back-off

    throws

    An error if fetch failed

    Parameters

    • url: string

      server request

    • opts: RequestInit

      fetch options

    • conf: IConfig

      configuration

    • attempt: number

      the retry attempt we are on

    Returns Promise<any>

    response from server

doGet

  • doGet(url: string, conf?: IConfig): Promise<any>
  • Perform GET request

    throws

    An error if GET fails

    Parameters

    • url: string

      server request

    • Default value conf: IConfig = CONFIG

      configuration

    Returns Promise<any>

    response from server

doIt

  • doIt(url: string, opts: RequestInit, conf: IConfig): Promise<any>
  • Do a server request

    throws

    An error if request failed

    Parameters

    • url: string

      server request

    • opts: RequestInit

      fetch options

    • conf: IConfig

      configuration

    Returns Promise<any>

    response from server

doPost

  • doPost(url: string, conf?: IConfig): Promise<any>
  • Perform POST request

    throws

    An error if POST fails

    Parameters

    • url: string

      server request

    • Default value conf: IConfig = CONFIG

      configuration

    Returns Promise<any>

    response from server

getAuthToken

  • getAuthToken(isAuth: boolean, interactive: boolean): Promise<null | string>
  • Get authorization token

    throws

    An error if we failed to get token

    Parameters

    • isAuth: boolean

      if true, authorization required

    • interactive: boolean

      if true, user initiated

    Returns Promise<null | string>

    auth token

getError

  • getError(response: Response): Error
  • Get Error message

    Parameters

    • response: Response

      server response

    Returns Error

    Error

processResponse

  • processResponse(response: Response, url: string, opts: RequestInit, conf: IConfig, attempt: number): Promise<any>
  • Check response and act accordingly, including retrying

    throws

    An error if fetch ultimately fails

    Parameters

    • response: Response

      server response

    • url: string

      server

    • opts: RequestInit

      fetch options

    • conf: IConfig

      configuration

    • attempt: number

      the retry attempt we are on

    Returns Promise<any>

    response from server

retry

  • retry(url: string, opts: RequestInit, conf: IConfig, attempt: number): Promise<any>
  • Retry authorized fetch with exponential back-off

    throws

    An error if fetch failed

    Parameters

    • url: string

      server request

    • opts: RequestInit

      fetch options

    • conf: IConfig

      configuration

    • attempt: number

      the retry attempt we are on

    Returns Promise<any>

    response from server

retryToken

  • retryToken(url: string, opts: RequestInit, conf: IConfig, attempt: number): Promise<any>
  • Retry fetch after removing cached auth token

    throws

    An error if fetch failed

    Parameters

    • url: string

      server request

    • opts: RequestInit

      fetch options

    • conf: IConfig

      configuration

    • attempt: number

      the retry attempt we are on

    Returns Promise<any>

    response from server

Object literals

Const CONFIG

CONFIG: object

Configuration object

backoff

backoff: true = true

body

body: null = null

checkConnection

checkConnection: true = true

interactive

interactive: false = false

isAuth

isAuth: false = false

json

json: true = true

maxRetries

maxRetries: number = MAX_RETRIES

retryToken

retryToken: false = false

token

token: null = null

Generated using TypeDoc