Fix error message and use new backend response
This commit is contained in:
parent
a8ae6be436
commit
250697448c
@ -23,10 +23,12 @@ export default {
|
|||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/discover/${game}`
|
`${protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/discover/${game}`
|
||||||
)
|
)
|
||||||
if (!res.ok) {
|
const rawData = await res.json()
|
||||||
return (this.data = { status: 'error' })
|
if (rawData.status === "ok") {
|
||||||
|
this.data = rawData.data
|
||||||
|
} else {
|
||||||
|
this.data = { status: 'error' }
|
||||||
}
|
}
|
||||||
this.data = await res.json()
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.data = { status: 'error' }
|
this.data = { status: 'error' }
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
@ -44,8 +44,6 @@ export default {
|
|||||||
const [set1, set2] = [new Set(wantedTags), new Set(tags)]
|
const [set1, set2] = [new Set(wantedTags), new Set(tags)]
|
||||||
const common = [...set1].filter((x) => set2.has(x))
|
const common = [...set1].filter((x) => set2.has(x))
|
||||||
|
|
||||||
console.log(wantedTags)
|
|
||||||
|
|
||||||
if (common.length === wantedTags.length) {
|
if (common.length === wantedTags.length) {
|
||||||
category.style.display = ''
|
category.style.display = ''
|
||||||
} else if (wantedTags[0] === '') {
|
} else if (wantedTags[0] === '') {
|
||||||
@ -91,10 +89,13 @@ export default {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${this.protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/discover`)
|
const res = await fetch(`${this.protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/discover`)
|
||||||
if (!res.ok) {
|
const rawData = await res.json()
|
||||||
throw new Error('Failed to fetch data')
|
if (rawData.status === "ok") {
|
||||||
|
this.data = rawData.data
|
||||||
|
} else {
|
||||||
|
this.data = { status: 'error' }
|
||||||
}
|
}
|
||||||
this.data = await res.json()
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
this.data = { status: 'error' }
|
this.data = { status: 'error' }
|
||||||
|
@ -12,22 +12,6 @@ export default {
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const username = route.params.username
|
const username = route.params.username
|
||||||
const protocol = import.meta.env.VITE_HTTPS === 'true' ? 'https://' : 'http://'
|
const protocol = import.meta.env.VITE_HTTPS === 'true' ? 'https://' : 'http://'
|
||||||
|
|
||||||
const getUser = async () => {
|
|
||||||
try {
|
|
||||||
const res = await fetch(
|
|
||||||
`${protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/users/${username}`
|
|
||||||
)
|
|
||||||
const data = await res.json()
|
|
||||||
return data
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
return {
|
|
||||||
status: 'error'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = ref()
|
const data = ref()
|
||||||
const videoOptions = {
|
const videoOptions = {
|
||||||
autoplay: true,
|
autoplay: true,
|
||||||
@ -46,7 +30,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
videoOptions,
|
videoOptions,
|
||||||
getUser
|
protocol
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
@ -57,8 +41,22 @@ export default {
|
|||||||
LoadingScreen
|
LoadingScreen
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
const fetchedUser = await this.getUser()
|
const username = this.$route.params.username
|
||||||
this.data = fetchedUser
|
const protocol = import.meta.env.VITE_HTTPS === 'true' ? 'https://' : 'http://'
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${protocol}${import.meta.env.VITE_BACKEND_DOMAIN}/api/users/${username}`)
|
||||||
|
const rawData = await res.json()
|
||||||
|
if (rawData.status === "ok") {
|
||||||
|
this.data = rawData.data
|
||||||
|
} else {
|
||||||
|
this.data = { status: 'error' }
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
this.data = { status: 'error' }
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
truncate(value: string, length: number) {
|
truncate(value: string, length: number) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user