-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1108 from City-of-Helsinki/UHF-9441-fetch-timeout
UHF-9441: Fetch timeout
- Loading branch information
Showing
30 changed files
with
195 additions
and
101 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/js/react/apps/school-search/hooks/UseConfigurationsQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import useSWR from 'swr'; | ||
import AppSettings from '../enum/AppSettings'; | ||
import { AGGREGATIONS } from '../helpers/FeatureQuery'; | ||
import useTimeoutFetch from '@/react/common/hooks/useTimeoutFetch'; | ||
|
||
const UseConfigurationsQuery = () => { | ||
const proxyUrl = drupalSettings?.helfi_react_search.elastic_proxy_url; | ||
const { index } = AppSettings; | ||
|
||
const body = JSON.stringify(AGGREGATIONS); | ||
|
||
const fetcher = async() => { | ||
const result = await useTimeoutFetch(`${proxyUrl}/${index}/_search`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body, | ||
}); | ||
|
||
if (!result.ok) { | ||
throw new Error('Initialization failed.'); | ||
} | ||
|
||
const data = await result.json(); | ||
|
||
const { aggregations } = data; | ||
|
||
if (!aggregations) { | ||
return { | ||
aggs: {}, | ||
baseUrl: proxyUrl | ||
}; | ||
} | ||
|
||
return { | ||
aggs: aggregations, | ||
baseUrl: proxyUrl | ||
}; | ||
}; | ||
|
||
const { data, error } = useSWR('configurations', fetcher, { | ||
revalidateOnFocus: false, | ||
revalidateIfStale: false, | ||
suspense: true | ||
}); | ||
|
||
return { | ||
data, | ||
error | ||
}; | ||
}; | ||
|
||
export default UseConfigurationsQuery; |
Oops, something went wrong.