Skip to content

Commit

Permalink
fix: catch fetch error on clone_from
Browse files Browse the repository at this point in the history
  • Loading branch information
abulte committed Jun 3, 2024
1 parent e638a58 commit ac817ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/custom/ecospheres/utils/bouquet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ export function useExtras(topic: Ref<Topic | null>): {
subtheme.value = topic.value?.extras['ecospheres:informations'][0].subtheme
datasetsProperties.value =
topic.value?.extras['ecospheres:datasets_properties'] ?? []
// FIXME: catch 404 when possible from data.gouv.fr
if (topic.value?.extras?.ecospheres?.cloned_from != null) {
useTopicStore()
.load(topic.value?.extras.ecospheres.cloned_from)
.load(topic.value?.extras.ecospheres.cloned_from, { toasted: false })
.then((res) => {
clonedFrom.value = res
})
.catch(() => {
.catch((err) => {
console.error('Failed fetching cloned_from', err.response?.data)
clonedFrom.value = null
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/model/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface RequestConfig extends CustomParams {

export type URLParams = Record<string, string | number | null>

interface BaseParams extends CustomParams {
export interface BaseParams extends CustomParams {
headers?: Record<string, unknown>
}

Expand Down
5 changes: 3 additions & 2 deletions src/store/TopicStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
import { computed, type ComputedRef } from 'vue'

import config from '@/config'
import type { BaseParams } from '@/model/api'
import type { TopicConf } from '@/model/config'
import type { Topic } from '@/model/topic'

Expand Down Expand Up @@ -116,10 +117,10 @@ export const useTopicStore = defineStore('topic', {
/**
* Get a single topic from store or API
*/
async load(slugOrId: string): Promise<Topic> {
async load(slugOrId: string, params?: BaseParams): Promise<Topic> {
const existing = this.get(slugOrId)
if (existing !== undefined) return existing
const topic = await topicsAPIv2.get({ entityId: slugOrId })
const topic = await topicsAPIv2.get({ entityId: slugOrId, ...params })
this.data.push(topic)
return topic
},
Expand Down

0 comments on commit ac817ee

Please sign in to comment.