axios#AxiosError TypeScript Examples
The following examples show how to use
axios#AxiosError.
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 |
/**
* 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 |
/**
* 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: utils.ts From SpaceEye with MIT License | 7 votes |
/**
* Format an Axios error object.
*
* @param error - Error to format
* @returns Formatted error
*/
export function formatAxiosError(error: AxiosError): string {
return `${error.code}\n${error.message}\n${error.stack}`
}
Example #4
Source File: utils.ts From discord-ifttt with MIT License | 6 votes |
function handleError(error: AxiosError, response: VercelResponse): void {
if (error.response) {
response.status(error.response.status).send(error.response.data)
} else {
response.status(400).send({error: error.message})
}
}
Example #5
Source File: generateIndex.ts From solana-program-registry with Apache License 2.0 | 6 votes |
fetchAndWriteIDL = async ({
indexDir,
release,
isLatest,
}: {
indexDir: string;
release: VerifiableProgramRelease;
isLatest: boolean;
}) => {
try {
const { data: idl } = await axios.get<Idl>(
buildURL({
slug: release.build.build.slug,
file: `idl/${release.program.name}.json`,
})
);
await fs.writeFile(
`${indexDir}releases/by-name/${release.id}.idl.json`,
JSON.stringify(idl)
);
if (isLatest) {
await fs.writeFile(
`${indexDir}idls/${release.program.address}.json`,
JSON.stringify(idl)
);
}
} catch (e) {
if ((e as AxiosError).response?.status !== 404) {
throw e;
}
console.warn(
`Could not find idl for ${release.build.build.repoName} ${release.build.build.tag}`
);
}
}
Example #6
Source File: berry.client.ts From pokenode-ts with MIT License | 6 votes |
/**
* 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));
});
}