diff --git a/package.json b/package.json index 792d13a..e7b0299 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/exceptions/sri_resolver_failiure.ts b/src/exceptions/sri_resolver_failiure.ts index 9147754..837b565 100644 --- a/src/exceptions/sri_resolver_failiure.ts +++ b/src/exceptions/sri_resolver_failiure.ts @@ -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; } } diff --git a/src/index.ts b/src/index.ts index 43605f0..8f3109d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; @@ -45,4 +45,4 @@ export function generateInvalidBioentities(input) { return generateInvalid(input); } -export const SRIResolverFailiure = SRIResolverFailiureImport; +export const SRINodeNormFailure = SRINodeNormFailureImport; diff --git a/src/sri.ts b/src/sri.ts index 5ddc566..77560a9 100644 --- a/src/sri.ts +++ b/src/sri.ts @@ -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) { @@ -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}`); } }