Skip to content

Commit

Permalink
Redirect 404 when OTU or Taxon name doesnt exist. Catch distribution …
Browse files Browse the repository at this point in the history
…error
  • Loading branch information
jlpereira committed Aug 7, 2023
1 parent 96d5c45 commit add9d68
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/modules/404/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import notFound from '../view/index.vue'

export default {
path: '/:pathMatch(.*)*',
name: 'notFound',
component: notFound
}
10 changes: 7 additions & 3 deletions src/modules/otus/helpers/useOtuPageRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ export function useOtuPageRequest(key, requestFunction) {
const store = useOtuPageRequestStore()
const request = requestFunction()

request.then((response) => {
store.setRequest(key, response)
})
request
.then((response) => {
store.setRequest(key, response)
})
.catch((error) => {
store.setRequest(key, error.response)
})

return request
}
11 changes: 9 additions & 2 deletions src/modules/otus/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ export const useOtuStore = defineStore('otuStore', {

requestStore.$reset()

await this.loadOtu(otuId)
await this.loadTaxon(this.otu.taxon_name_id)
try {
await this.loadOtu(otuId)
await this.loadTaxon(this.otu.taxon_name_id)
} catch (error) {
return false
}

await this.loadCatalog(this.otu.taxon_name_id)
await this.loadTaxonomy(otuId)

return true
},

async loadImages(otuId) {
Expand Down
9 changes: 7 additions & 2 deletions src/modules/otus/views/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ onBeforeUnmount(() => {
async function loadInitialData() {
store.$reset()
await store.loadInit(route.params.id)
updateMetadata()
const success = await store.loadInit(route.params.id)
if (success) {
updateMetadata()
} else {
router.replace({ name: 'notFound' })
}
}
function updateMetadata() {
Expand Down

0 comments on commit add9d68

Please sign in to comment.