axios#AxiosResponse TypeScript Examples

The following examples show how to use axios#AxiosResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utility.client.ts    From pokenode-ts with MIT License 7 votes vote down vote up
/**
   * Get a Language by it's ID
   * @param id The Language ID
   * @returns Language
   */
  public async getLanguageById(id: number): Promise<Language> {
    return new Promise<Language>((resolve, reject) => {
      this.api
        .get<Language>(`${Endpoints.Language}/${id}`)
        .then((response: AxiosResponse<Language>) => resolve(response.data))
        .catch((error: AxiosError<string>) => reject(error));
    });
  }
Example #2
Source File: index.ts    From insta-fetcher with GNU General Public License v3.0 7 votes vote down vote up
/**
	 * Make request to IG API
	 * @param baseURL 
	 * @param url 
	 * @param agent 
	 * @param options 
	 */
	private FetchIGAPI = (baseURL: string, url: string = '', agent: string = config.android, options: AxiosRequestConfig = {}): Promise<AxiosResponse> | undefined => {
		try {
			return axios({
				baseURL,
				url,
				headers: options.headers ? options.headers : this.buildHeaders(agent),
				method: options.method || 'GET',
				...options
			});
		} catch (error: any | AxiosError) {
			if (axios.isAxiosError(error)) {
				throw error.response
			}
		}
	}
Example #3
Source File: FileDataItem.ts    From arbundles with Apache License 2.0 6 votes vote down vote up
/**
   * @deprecated Since version 0.3.0. Will be deleted in version 0.4.0. Use @bundlr-network/client package instead to interact with Bundlr
   */
  public async sendToBundler(bundler: string): Promise<AxiosResponse> {
    const headers = {
      "Content-Type": "application/octet-stream",
    };

    if (!this.isSigned())
      throw new Error("You must sign before sending to bundler");
    const response = await axios.post(
      `${bundler}/tx`,
      fs.createReadStream(this.filename),
      {
        headers,
        timeout: 100000,
        maxBodyLength: Infinity,
        validateStatus: (status) =>
          (status > 200 && status < 300) || status !== 402,
      },
    );

    if (response.status === 402)
      throw new Error("Not enough funds to send data");

    return response;
  }
Example #4
Source File: ipfs.ts    From dxvote with GNU Affero General Public License v3.0 6 votes vote down vote up
getIPFSFile = async function (
  ipfsHash,
  timeout = 1000
): Promise<AxiosResponse<any>> {
  try {
    return await Promise.any([
      axios.request({
        url: 'https://ipfs.io/ipfs/' + ipfsHash,
        method: 'GET',
        timeout: timeout,
      }),
      axios.request({
        url: 'https://gateway.ipfs.io/ipfs/' + ipfsHash,
        method: 'GET',
        timeout: timeout,
      }),
      axios.request({
        url: 'https://gateway.pinata.cloud/ipfs/' + ipfsHash,
        method: 'GET',
        timeout: timeout,
      }),
      axios.request({
        url: 'https://dweb.link/ipfs/' + ipfsHash,
        method: 'GET',
        timeout: timeout,
      }),
      axios.request({
        url: 'https://infura-ipfs.io/ipfs/' + ipfsHash,
        method: 'GET',
        timeout: timeout,
      }),
    ]);
  } catch (e) {
    console.warn(e);
    return undefined;
  }
}
Example #5
Source File: testing.d.ts    From openapi-cop with MIT License 6 votes vote down vote up
/**
 * For each OpenAPI file in a given directory, it boots a proxy and a mock
 * server and runs the provided test requests. It then executes the callback
 * function that contains the test code.
 */
export declare function testRequestForEachFile({ testTitle, dir, testRequests, client, callback, defaultForbidAdditionalProperties, silent, }: {
    testTitle: string;
    dir: string;
    testRequests: TestRequests;
    client: {
        proxy: AxiosInstance;
        target: AxiosInstance;
    };
    callback: (proxyRes: AxiosResponse, targetRes: AxiosResponse, fileName: string, requestObject: TestRequestConfig) => void;
    defaultForbidAdditionalProperties?: boolean;
    silent?: boolean;
}): void;
Example #6
Source File: JSONMapperUtilities.ts    From personal-dj with MIT License 6 votes vote down vote up
mapJSONTrackSearchToModel = (data: AxiosResponse) => {
    let results = new Map<string, SearchResultModel>();
    // This fat try catch makes me feel sick
    try {
        let searchResultsAsJSON = data.data.trackResult.tracks.items;
        // Parse JSON and create them into components
        for (let i = 0; i < searchResultsAsJSON.length; i++) {
            let tempImgUrl = searchResultsAsJSON[i].album.images[0].url || image404_url;
            let tempTitle = searchResultsAsJSON[i].name || "Title Not Found";
            let tempArtistName =
                searchResultsAsJSON[i].artists[0].name || "Artist Not Found";
            let tempTrackId: string = searchResultsAsJSON[i].id;
            // Add all results to explicit list (both explicit and non explicit)
            results.set(tempTrackId,
                {
                    trackId: tempTrackId,
                    title: tempTitle,
                    imgUrl: tempImgUrl,
                    artistName: tempArtistName,
                });
        }
    } catch (e) {
        console.error("Failed to convert track result response to model", e);
        handleError({message: "401"});
    }
    return results;
}
Example #7
Source File: berry.client.ts    From pokenode-ts with MIT License 6 votes vote down vote up
/**
   * Get a Berry by it's name
   * @param name The berry name
   * @returns A Berry
   */
  public async getBerryByName(name: string): Promise<Berry> {
    return new Promise<Berry>((resolve, reject) => {
      this.api
        .get<Berry>(`${Endpoints.Berry}/${name}`)
        .then((response: AxiosResponse<Berry>) => resolve(response.data))
        .catch((error: AxiosError<string>) => reject(error));
    });
  }