Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors in attribute query #113

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/attrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ function buildOneQuery(
const returnFields = idReturnFields + attrReturnFields;
const scopes = getInputScopes(metadata.mapping, prefix);
debug(`inputs ${inputs}`);
const userAgent = `BTE/${process.env.NODE_ENV === 'production' ? 'prod' : 'dev'} Node/${process.version} ${
process.platform
}`;
const userAgent = `BTE/${process.env.NODE_ENV === 'production' ? 'prod' : 'dev'} Node/${process.version} ${process.platform
}`;
return axios({
method: 'post',
url: metadata.url,
Expand All @@ -136,10 +135,17 @@ function buildOneQuery(
'content-type': 'application/json',
'User-Agent': userAgent,
},
}).then((response) => getDBIDs(prefix, semanticType, response.data));
})
.then((response) => getDBIDs(prefix, semanticType, response.data))
.catch(() => undefined);
}

function buildQueries(metadata: MetaDataObject, prefix: string, inputs: string[], semanticType: string) {
function buildQueries(
metadata: MetaDataObject,
prefix: string,
inputs: string[],
semanticType: string,
): Promise<IndividualResolverOutput>[] {
if (inputs.length > MAX_BIOTHINGS_INPUT_SIZE) {
return _.chunk(inputs, MAX_BIOTHINGS_INPUT_SIZE).map((batch) =>
buildOneQuery(metadata, prefix, batch, semanticType),
Expand All @@ -153,9 +159,9 @@ function getAPIMetaData(semanticType: string) {
return APIMETA[semanticType];
}

function build(semanticType: string, curies: string[]) {
function build(semanticType: string, curies: string[]): Promise<IndividualResolverOutput>[] {
const grped = groupCuriesByPrefix(curies);
return Object.keys(grped).reduce((prev, current) => {
return Object.keys(grped).reduce((prev: Promise<IndividualResolverOutput>[], current) => {
prev = [...prev, ...buildQueries(getAPIMetaData(semanticType), current, grped[current], semanticType)];
return prev;
}, []);
Expand All @@ -177,7 +183,7 @@ function getSupportedType(category: string): string {

export async function _getAttributes(idsByType: object): Promise<any> {
debug(`Adding attributes of ${JSON.stringify(idsByType)}`);
let promises = [];
let promises: Promise<IndividualResolverOutput>[] = [];
for (const type in idsByType) {
const ids = idsByType[type];
const supportedType = getSupportedType(type);
Expand All @@ -190,9 +196,10 @@ export async function _getAttributes(idsByType: object): Promise<any> {
}
}
}
let res: any = await Promise.all(promises);
let res: IndividualResolverOutput[] = await Promise.all(promises);
let merged = {};
res.forEach((res_obj) => {
if (typeof res_obj === 'undefined') return;
merged = {
...merged,
...res_obj,
Expand Down
Loading