Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry on permalink failure. #237

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions pages/apps/maps/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ const restoreStateWithUUID = async (route, $axios, sparcApi) => {
let state = undefined
let successMessage = undefined
let failMessage = undefined
if (route.query.id) {
uuid = route.query.id
const maxRetry = 3
const getState = async (uuid) => {
await $axios.post(`${sparcApi}/map/getstate`, {
uuid: uuid,
})
Expand All @@ -254,7 +254,15 @@ const restoreStateWithUUID = async (route, $axios, sparcApi) => {
`Sorry! We can not retrieve the saved stated. Please check later or consider submitting a bug report.`
})
}

if (route.query.id) {
uuid = route.query.id
for (let attempt = 0; attempt < maxRetry && !successMessage; attempt++) {
await getState(uuid)
}
}
if (successMessage) {
failMessage = undefined
}
return [uuid, state, successMessage, failMessage]
}

Expand Down Expand Up @@ -413,20 +421,38 @@ export default {
updateUUID: function () {
let url = this.options.sparcApi + `map/getshareid`
let state = this._instance.getState()
fetch(url, {
let maxRetry = 3
const getShareLink = (attempt) => {
fetch(url, {
method: 'POST',
headers: {
'Content-type': 'application/json',
},
body: JSON.stringify({ state: state }),
})
.then((response) => response.json())
.then((response) => {
if (response.ok) {
return response.json()
}
throw new Error('Unsuccessful attempt to get shareid')
})
.then((data) => {
this.uuid = data.uuid
this.$router.replace({ query: { id: data.uuid } }).then(() => {
this.shareLink = `${this.options.rootUrl}${this.$route.fullPath}`
})
})
.catch((error) => {
console.log(`Unable to create permalink: attempt ${attempt} of ${maxRetry}`)
if (maxRetry > attempt) {
getShareLink(attempt + 1)
} else {
this.shareLink = `We have encountered an error, please try again.`
failMessage("We are unable to create a permalink at this moment, please try again later.")
}
})
}
getShareLink(1)
},
facetsUpdated: function () {
if (this.facets.length > 0 && this._instance) this._instance.openSearch(this.facets, "")
Expand Down
Loading