Fetch with authentication and exponential back-off
- Source:
Members
-
<private, static, constant> _AUTH_HEADER :string
-
Authorization header
Type:
- string
- Source:
-
<private, static, constant> _BEARER :string
-
Bearer parameter for authorized call
Type:
- string
- Source:
-
<private, static, constant> _CONFIG :Chrome.Http.Config
-
Configuration object
Type:
- Source:
-
<private, static, constant> _DELAY
-
Delay multiplier for exponential back-off
- Source:
-
<private, static, constant> _MAX_RETRIES :int
-
Max retries on 500 errors
Type:
- int
- Source:
Methods
-
<private, static> _doIt(url, opts, conf) → {Promise.<JSON>}
-
Do a server request
Parameters:
Name Type Description url
string server request
opts
Object fetch options
conf
Chrome.Http.Config configuration
- Source:
Returns:
response from server
- Type
- Promise.<JSON>
-
<private, static> _fetch(url, opts, conf, attempt) → {Promise.<JSON>}
-
Perform fetch, optionally using authorization and exponential back-off
Parameters:
Name Type Description url
string server request
opts
Object fetch options
conf
Chrome.Http.Config configuration
attempt
int the retry attempt we are on
- Source:
Returns:
response from server
- Type
- Promise.<JSON>
-
<private, static> _getAuthToken(isAuth, interactive) → {Promise.<string>}
-
Get authorization token
Parameters:
Name Type Description isAuth
boolean if true, authorization required
interactive
boolean if true, user initiated
- Source:
Returns:
auth token
- Type
- Promise.<string>
-
<private, static> _getError(response) → {Error}
-
Get Error message
Parameters:
Name Type Description response
Chrome.Http.Response server response
- Source:
Returns:
- Type
- Error
-
<private, static> _processResponse(response, url, opts, conf, attempt) → {Promise.<JSON>}
-
Check response and act accordingly
Parameters:
Name Type Description response
Chrome.Http.Response server response
url
string server
opts
Object fetch options
conf
Chrome.Http.Config configuration
attempt
int the retry attempt we are on
- Source:
Returns:
response from server
- Type
- Promise.<JSON>
-
<private, static> _retry(url, opts, conf, attempt) → {Promise.<JSON>}
-
Retry authorized fetch with exponential back-off
Parameters:
Name Type Description url
string server request
opts
Object fetch options
conf
Chrome.Http.Config configuration
attempt
int the retry attempt we are on
- Source:
Returns:
response from server
- Type
- Promise.<JSON>
-
<private, static> _retryToken(url, opts, conf, attempt) → {Promise.<JSON>}
-
Retry fetch after removing cached auth token
Parameters:
Name Type Description url
string server request
opts
Object fetch options
conf
Chrome.Http.Config configuration
attempt
int the retry attempt we are on
- Source:
Returns:
response from server
- Type
- Promise.<JSON>
-
<static> doGet(url [, conf]) → {Promise.<JSON>}
-
Perform GET request
Parameters:
Name Type Argument Default Description url
string server request
conf
Chrome.Http.Config <optional>
null configuration
- Source:
Returns:
response from server
- Type
- Promise.<JSON>
-
<static> doPost(url [, conf]) → {Promise.<JSON>}
-
Perform POST request
Parameters:
Name Type Argument Default Description url
string server request
conf
Chrome.Http.Config <optional>
null configuration
- Source:
Returns:
response from server
- Type
- Promise.<JSON>
Type Definitions
-
Config
-
Http configuration
Type:
- Object
- Source:
Properties:
Name Type Argument Default Description isAuth
boolean <optional>
false if true, authorization required
retryToken
boolean <optional>
false if true, retry with new token
interactive
boolean <optional>
false user initiated, if true
token
string <optional>
<nullable>
null auth token
backoff
boolean <optional>
true if true, do exponential back-off
maxRetries
int <optional>
_MAX_ATTEMPTS max retries
-
Response
-
Http response
Type:
- Object
- Source:
Properties:
Name Type Description ok
boolean success flag
json
function returned data as JSON
status
int HTTP response code
statusText
string HTTP response message