Skip to content

Commit

Permalink
Merge pull request #107 from biothings/retry-sri
Browse files Browse the repository at this point in the history
retry failed sri requests
  • Loading branch information
tokebe authored Nov 2, 2023
2 parents 9421638 + ae86624 commit 53f5cc0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"dependencies": {
"@commitlint/cli": "^17.8.1",
"@commitlint/config-conventional": "^11.0.0",
"axios-retry": "^3.8.0",
"axios": "^0.21.4",
"biolink-model": "file:../biolink-model",
"debug": "^4.3.4",
Expand Down
9 changes: 5 additions & 4 deletions src/exceptions/sri_resolver_failiure.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
export default class SRIResolverFailiure extends Error {
export default class SRINodeNormFailure extends Error {

constructor(message = 'SRI Resolver Failed.', ...params) {
super(...params);

Object.setPrototypeOf(this, SRIResolverFailiure.prototype);
Object.setPrototypeOf(this, SRINodeNormFailure.prototype);

if (Error.captureStackTrace) {
Error.captureStackTrace(this, SRIResolverFailiure);
Error.captureStackTrace(this, SRINodeNormFailure);
}

this.name = 'SRIResolverFailiure';
this.name = 'SRINodeNormFailure';
this.message = message;
}
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { APIMETA } from './config';
import generateInvalid from './fake';
import { _resolveSRI } from './sri';
import { _getAttributes } from './attrs';
import SRIResolverFailiureImport from './exceptions/sri_resolver_failiure';
import SRINodeNormFailureImport from './exceptions/sri_resolver_failiure';

export * from './common/types';

Expand Down Expand Up @@ -45,4 +45,4 @@ export function generateInvalidBioentities(input) {
return generateInvalid(input);
}

export const SRIResolverFailiure = SRIResolverFailiureImport;
export const SRINodeNormFailure = SRINodeNormFailureImport;
11 changes: 9 additions & 2 deletions src/sri.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import axios from 'axios';
import axiosRetry from 'axios-retry';
import { CURIE } from './config';
import { SRIResolverOutput, ResolverInput, SRIBioEntity, SRIResponseEntity, SRIResponse } from './common/types';
import Debug from 'debug';
import _ from 'lodash';
import SRIResolverFailiure from './exceptions/sri_resolver_failiure';
import SRINodeNormFailure from './exceptions/sri_resolver_failiure';
const debug = Debug('bte:biomedical-id-resolver:SRI');

/** sets up request retry policy (weird typescript b/c old axios version) */
// @ts-ignore
axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay, retryCondition: (err) => {
return axiosRetry.isNetworkOrIdempotentRequestError(err) || err.response?.status >= 500;
} })

/** convert object of arrays into array of unique IDs */
function combineInputs(userInput: ResolverInput): string[] {
const result = Object.keys(userInput).reduce(function (r, k) {
Expand Down Expand Up @@ -36,7 +43,7 @@ async function query(api_input: string[]) {
});
return Object.assign({}, ...res);
} catch (err) {
throw new SRIResolverFailiure(`SRI resolver failed: ${err.message}`);
throw new SRINodeNormFailure(`SRI resolver failed: ${err.message}`);
}
}

Expand Down

0 comments on commit 53f5cc0

Please sign in to comment.