Skip to content

Commit

Permalink
add timeout to fcbh getResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Jan 10, 2025
1 parent bc61e60 commit 0ba09d5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
23 changes: 18 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"normalize.css": "^8.0.1",
"p-memoize": "^7.1.1",
"p-throttle": "^7.0.0",
"p-timeout": "^6.1.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-intl": "^6.6.8",
Expand Down
10 changes: 7 additions & 3 deletions src/services/fcbh/getResponse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pMemoize from 'p-memoize';
import pThrottle from 'p-throttle';
import pTimeout from 'p-timeout';

const API_URL = 'https://4.dbt.io/api';
const API_KEY = process.env.BIBLE_BRAIN_KEY;
Expand All @@ -9,9 +10,12 @@ const throttle = pThrottle({ limit: 50, interval: 1000 });
async function getResponse<T extends Record<string, unknown>>(
route: string,
): Promise<T | null> {
const result = await fetch(`${API_URL}${route}&v=4&key=${API_KEY}`, {
method: 'GET',
});
const result = await pTimeout(
fetch(`${API_URL}${route}&v=4&key=${API_KEY}`, {
method: 'GET',
}),
{ milliseconds: 5000 },
);

const text = await result.text();

Expand Down

0 comments on commit 0ba09d5

Please sign in to comment.