resource-access.js
/**
 Arrange to handle the outcome of an HTTP-based request, made the fetch API.
 Interpret the response state to retry authentication failures and accept any
 success code to cause the response to flow to the success continuation.
 401 requests authentication information interactively, augments the given options
 with new authentication information and invokes the retry continuation.
 Any other condition invokes the fail continuation if one is provided.
 */
Arrange to handle the outcome of an HTTP-based request, made the fetch API.
Interpret the response state to retry authentication failures and accept any
success code to cause the response to flow to the success continuation.
401 requests authentication information interactively, augments the given options
with new authentication information and invokes the retry continuation.
Any other condition invokes the fail continuation if one is provided.
Arrange to handle the outcome of an HTTP - based request made the fetch API . Interpret the response state to retry authentication failures and accept any success code to cause the response to flow to the success continuation . 401 requests authentication information interactively augments the given options with new authentication information and invokes the retry continuation . Any other condition invokes the fail continuation if one is provided .
function responseHandler (location, options, succeed, retry, fail) {
  var savedAuth = responseHandler.getAuthentication(location);
  var optionsAuth = options.authentication;
  if (savedAuth && !optionsAuth) {
    Object.assign(options, {authentication: savedAuth});
  }
  function ensureSuccessfulResponse (response) {
    log.debug("ensureSuccessfulResponse: ", response);
    if (response instanceof Response) {
      if (response.ok) {
        log.debug(response.status, location);
        succeed(response);
      } else if (response.status == 401) {
        log.warn("responseHandler: 401: ", location);
        function localRetry(authentication) {
          responseHandler.setAuthentication(location, authentication);
          options = Object.assign({}, options, {authentication: authentication});
          log.debug("esr: augmented options: ", options);
          retry(options);
        }
        log.debug("prompt: ", localRetry);
        authentication_token_prompt({location: location, submit: localRetry});
      } else {
        log.debug(`responseHandler ${location}: ${response.status}`);
        if (fail) { fail(response); }
      }
    } else {
      if (fail) { fail(response); }
    }
  }
  return ( ensureSuccessfulResponse );
}
function responseHandler ( location , options , succeed , retry , fail ) { var savedAuth = responseHandler . getAuthentication ( location ) ; var optionsAuth = options . authentication ; if ( savedAuth && ! optionsAuth ) { Object . assign ( options , { authentication : savedAuth } ) ; } function ensureSuccessfulResponse ( response ) { log . debug ( "ensureSuccessfulResponse: " , response ) ; if ( response instanceof Response ) { if ( response . ok ) { log . debug ( response . status , location ) ; succeed ( response ) ; } else if ( response . status == 401 ) { log . warn ( "responseHandler: 401: " , location ) ; function localRetry ( authentication ) { responseHandler . setAuthentication ( location , authentication ) ; options = Object . assign ( { } , options , { authentication : authentication } ) ; log . debug ( "esr: augmented options: " , options ) ; retry ( options ) ; } log . debug ( "prompt: " , localRetry ) ; authentication_token_prompt ( { location : location , submit : localRetry } ) ; } else { log . debug ( ` ${ location } ${ response . status } ` ) ; if ( fail ) { fail ( response ) ; } } } else { if ( fail ) { fail ( response ) ; } } } return ( ensureSuccessfulResponse ) ; }
Arrange to handle the outcome of an HTTP-based request, made the fetch API.
Arrange to handle the outcome of an HTTP - based request made the fetch API .
// a failed response aborts references to the text body