Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return rp.args.urls.map(async url => {
const res = await fetch(url);
const data = await res.json();
return data;
});
},
const result = await retryIf(() => fetch(url, { timeout }), {
retryThenIf: r => r.status >= 500 && r.status < 600,
linkAccount(accountLinkingToken) {
const finalUrl = this.constructor.buildURL('me', {
access_token: this.pageAccessToken,
fields: 'recipient',
account_linking_token: accountLinkingToken,
});
return fetch(finalUrl, {
headers: {
'Content-Type': 'application/json',
},
})
.then(response => response.json());
}
private async getList(message: Discord.Message) {
const response = await fetch(this.settings.riotApiLibraries.baseURL, this.fetchSettings);
if (response.status !== 200) {
message.channel.send(this.settings.riotApiLibraries.githubErrorList + response.status);
return;
}
const data = await response.json() as GithubAPIStruct[];
const languages = "`" + data.map(x => x.name).join(", ") + "`";
const reply = this.settings.riotApiLibraries.languageList.replace("{languages}", languages);
message.channel.send(reply);
}
function fetchRequest(url: string, options: RequestHandlerOption, callback: RequestCallback): void {
const fetchOptions = {
headers: {
Accept: 'application/json',
},
} as NodeRequestInit;
if (options && options.proxyAgent) {
fetchOptions.agent = options.proxyAgent;
}
fetch(url, fetchOptions).then((xhr) => {
if (~~(xhr.status / 100 !== 2)) {
/**
* @description
* drain the xhr before throwing an error to prevent memory leaks
* @link https://github.com/bitinn/node-fetch/issues/83
*/
return xhr.text().then(() => {
const e: any = new Error(`Unexpected status code [${xhr.status}] on URL ${url}`);
e.status = xhr.status;
throw e;
});
} else {
return xhr.json().then((result) => {
const cacheControl = xhr.headers.get('cache-control');
const parsedCacheControl = cacheControl ? /max-age=(\d+)/.exec(cacheControl) : null;
const ttl = parsedCacheControl ? parseInt(parsedCacheControl[1], 10) : undefined;
export async function getXappToken(): Promise {
const clientAndSecret = `client_id=${ARTSY_API_CLIENT}&client_secret=${ARTSY_API_SECRET}`
return fetch(`${GRAVITY_URL}${GravityXappAPI}?${clientAndSecret}`)
.then(checkStatus)
.then(parseJSON)
}
export const onBrainlife = async dataset => {
try {
const url = `https://brainlife.io/api/warehouse/project?find={"openneuro.dataset_id":"${dataset.id}"}`
const res = await fetch(url)
const body = await res.json()
return Boolean(body.count)
} catch (err) {
return false
}
}
export default async function expandAuthToken(token) {
const response = await fetch(HYDRA_OAUTH2_INTROSPECT_URL, {
headers: { "Content-Type": "application/x-www-form-urlencoded" },
method: "POST",
body: qs.stringify({ token })
});
if (!response.ok) {
throw new ReactionError("access-denied", "Error introspecting token");
}
return response.json();
}