Home Reference Source Test Repository
import FetchUtil from '@npr/npr-one-sdk/util/fetch-util.js'
public class | source

FetchUtil

A thin wrapper around the Fetch API which provides functionality to automatically request a new access token if an existing one has expired.

Static Method Summary

Static Public Methods
public static

Wraps an error response from an API call in an ApiError object so that consuming code has more flexibility to determine how to handle the error.

public static

nprApiFetch(url: string, options: Object): Promise<Object>

Primary workhorse for interacting with the NPR One APIs.

Static Public Methods

public static formatErrorResponse(response: Response): Promise source

Wraps an error response from an API call in an ApiError object so that consuming code has more flexibility to determine how to handle the error. To be clear: this function returns a Promise that always rejects, but it may or may not have the deserialized JSON body based on whether response.json() succeeded or failed (the latter is usually an indicator that the response had an empty body).

Params:

NameTypeAttributeDescription
response Response

Return:

Promise

public static nprApiFetch(url: string, options: Object): Promise<Object> source

Primary workhorse for interacting with the NPR One APIs.

Params:

NameTypeAttributeDescription
url string
options Object
  • optional

Return:

Promise<Object>