1
0
Fork 0
mirror of synced 2024-10-02 10:08:09 +13:00

Add onMigrationDetected function

This commit is contained in:
Adria Navarro 2023-12-12 13:42:01 +01:00
parent 005dd27663
commit 50da799216

View file

@ -63,6 +63,11 @@ const defaultAPIClientConfig = {
* invoked before the actual JS error is thrown up the stack.
*/
onError: null,
/**
* A function can be passed to be called when an API call returns info about a migration running for a specific app
*/
onMigrationDetected: null,
}
/**
@ -171,6 +176,7 @@ export const createAPIClient = config => {
// Handle response
if (response.status >= 200 && response.status < 400) {
handleMigrations(response)
try {
if (parseResponse) {
return await parseResponse(response)
@ -187,7 +193,18 @@ export const createAPIClient = config => {
}
}
// Performs an API call to the server and caches the response.
const handleMigrations = response => {
if (!config.onMigrationDetected) {
return
}
const migration = response.headers.get(Header.MIGRATING_APP)
if (migration) {
config.onMigrationDetected(migration)
}
}
// Performs an API call to the server and caches the response.
// Future invocation for this URL will return the cached result instead of
// hitting the server again.
const makeCachedApiCall = async params => {