Skip to content

Commit 0898023

Browse files
committed
Handle 404
1 parent c1c8d33 commit 0898023

File tree

11 files changed

+48
-38
lines changed

11 files changed

+48
-38
lines changed

error.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ const getGithubIssueLink = computed(() => {
5151
<Text v-if="error?.statusCode == 404" size="16" weight="500" color="secondary">
5252
{{ error?.statusMessage }}
5353
</Text>
54+
<!-- <Flex v-if="error?.statusCode == 404" direction="column" gap="6">
55+
<Text size="16" weight="500" color="secondary">
56+
{{ error?.statusMessage }}
57+
</Text>
58+
59+
<Text v-if="error?.data?.value" size="16" weight="500" color="secondary">
60+
{{ error?.statusMessage }}
61+
</Text>
62+
</Flex> -->
5463
<Text v-else size="16" weight="500" color="secondary"> Unknown Error </Text>
5564

5665
<Text

pages/address/[hash].vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ const route = useRoute()
1818
const router = useRouter()
1919
2020
const address = ref()
21-
const hash = route.params.hash.startsWith("0x") ? route.params.hash.slice(2) : route.params.hash
22-
if (isValidId(hash, "address")) {
23-
const { data: rawAddress } = await fetchAddressByHash(hash)
21+
22+
if (isValidId(route.params.hash, "address")) {
23+
const { data: rawAddress } = await fetchAddressByHash(route.params.hash)
2424
2525
if (!rawAddress.value) {
26-
router.push("/")
26+
throw createError({ statusCode: 404, statusMessage: `Address ${route.params.hash} not found` })
2727
} else {
2828
address.value = rawAddress.value
2929
cacheStore.current.address = address.value
3030
}
3131
} else {
32-
router.push("/")
32+
throw createError({ statusCode: 404, statusMessage: `Address ${route.params.hash} not found` })
3333
}
3434
3535
defineOgImageComponent("AddressImage", {

pages/block/[height].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const route = useRoute()
2020
const block = ref()
2121
2222
if (!isValidId(route.params.height, "block")) {
23-
navigateTo("/")
23+
throw createError({ statusCode: 404, statusMessage: `Block ${route.params.height} not found` })
2424
}
2525
2626
const { data: rawBlock } = await fetchBlockByHeight(route.params.height)

pages/ibc/chain/[id].vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ import { IbcChainName } from "@/services/constants/ibc"
99
import { fetchIbcChainsStats } from "@/services/api/stats"
1010
1111
const route = useRoute()
12-
const router = useRouter()
1312
1413
const { data } = await useAsyncData(`ibc-chains`, () => fetchIbcChainsStats({ limit: 100 }))
1514
const chain = ref(data.value.find((c) => c.chain === route.params.id))
1615
1716
if (!chain.value) {
18-
router.push("/")
17+
throw createError({ statusCode: 404, statusMessage: `IBC chain ${route.params.id} not found` })
1918
}
2019
2120
useHead({

pages/namespace/[id].vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,20 @@ import { useCacheStore } from "@/store/cache.store"
1414
const cacheStore = useCacheStore()
1515
1616
const route = useRoute()
17-
const router = useRouter()
1817
1918
const namespace = ref()
2019
2120
if (isValidId(route.params.id, "namespace")) {
2221
const { data: rawNamespace } = await fetchNamespaceByID(route.params.id)
2322
2423
if (!rawNamespace.value) {
25-
router.push("/")
24+
throw createError({ statusCode: 404, statusMessage: `Namespace ${route.params.id} not found` })
2625
} else {
2726
namespace.value = rawNamespace.value[0]
2827
cacheStore.current.namespace = namespace.value
2928
}
3029
} else {
31-
router.push("/")
30+
throw createError({ statusCode: 404, statusMessage: `Namespace ${route.params.id} not found` })
3231
}
3332
3433
defineOgImageComponent("NamespaceImage", {

pages/network/[slug].vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ const appStore = useAppStore()
1616
const cacheStore = useCacheStore()
1717
1818
const route = useRoute()
19-
const router = useRouter()
2019
2120
const rollup = ref()
2221
const { data: rawRollup } = await fetchRollupBySlug(route.params.slug)
2322
2423
if (!rawRollup.value) {
25-
router.push("/networks")
24+
throw createError({ statusCode: 404, statusMessage: `Network ${route.params.slug} not found` })
2625
} else {
2726
rollup.value = rawRollup.value
2827
patchRollupColor()

pages/network/rank/[slug].vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ async function fetchData() {
9292
fetchRollupRankingBySlug(slug),
9393
])
9494
95+
if (!rollupData?.data?.value) {
96+
throw createError({ statusCode: 404, statusMessage: `Network ${slug} not found` })
97+
}
98+
9599
let description = []
96100
for (const [key, value] of Object.entries(rankData?.scores)) {
97101
const category = getMetricCategory(key, value)
@@ -244,7 +248,7 @@ const handleHowItWorksClick = () => {
244248
watch(
245249
() => page.value,
246250
async () => {
247-
repos.value = await getRollupRepos(rollup.value.slug)
251+
repos.value = await getRollupRepos(rollup.value?.slug)
248252
},
249253
)
250254

pages/proposal/[id].vue

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,29 @@ if (isValidId(route.params.id, "proposal")) {
2222
const { data: rawProposal } = await fetchProposalById({ id: route.params.id })
2323
2424
if (!rawProposal.value) {
25-
navigateTo({
26-
path: "/",
27-
query: {
28-
error: "not_found",
29-
target: "proposal",
30-
id: route.params.id,
31-
},
32-
})
25+
throw createError({ statusCode: 404, statusMessage: `Proposal ${route.params.id} not found` })
26+
// navigateTo({
27+
// path: "/",
28+
// query: {
29+
// error: "not_found",
30+
// target: "proposal",
31+
// id: route.params.id,
32+
// },
33+
// })
3334
} else {
3435
proposal.value = rawProposal.value
3536
cacheStore.current.proposal = proposal.value
3637
}
3738
} else {
38-
navigateTo({
39-
path: "/",
40-
query: {
41-
error: "not_found",
42-
target: "proposal",
43-
id: route.params.id,
44-
},
45-
})
39+
throw createError({ statusCode: 404, statusMessage: `Proposal ${route.params.id} not found` })
40+
// navigateTo({
41+
// path: "/",
42+
// query: {
43+
// error: "not_found",
44+
// target: "proposal",
45+
// id: route.params.id,
46+
// },
47+
// })
4648
}
4749
4850
defineOgImageComponent("ProposalImage", {

pages/tx/[hash].vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,19 @@ import { useCacheStore } from "@/store/cache.store"
1414
const cacheStore = useCacheStore()
1515
1616
const route = useRoute()
17-
const router = useRouter()
1817
1918
const tx = ref()
2019
const hash = route.params.hash.startsWith("0x") ? route.params.hash.slice(2) : route.params.hash
2120
if (isValidId(hash, "tx")) {
2221
const { data: rawTx } = await fetchTxByHash(hash)
2322
if (!rawTx.value) {
24-
router.push("/")
23+
throw createError({ statusCode: 404, statusMessage: `Transaction ${route.params.hash} not found` })
2524
} else {
2625
tx.value = rawTx.value
2726
cacheStore.current.transaction = tx.value
2827
}
2928
} else {
30-
router.push("/")
29+
throw createError({ statusCode: 404, statusMessage: `Transaction ${route.params.hash} not found` })
3130
}
3231
3332
defineOgImageComponent("TxImage", {

pages/validator/[id].vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,19 @@ import { useCacheStore } from "@/store/cache.store"
1313
const cacheStore = useCacheStore()
1414
1515
const route = useRoute()
16-
const router = useRouter()
1716
1817
const validator = ref()
1918
if (isValidId(route.params.id, "validator")) {
2019
const { data: rawValidator } = await fetchValidatorByID(route.params.id)
2120
2221
if (!rawValidator.value) {
23-
router.push("/")
22+
throw createError({ statusCode: 404, statusMessage: `Validator ${route.params.id} not found` })
2423
} else {
2524
validator.value = rawValidator.value
2625
cacheStore.current.validator = validator.value
2726
}
2827
} else {
29-
router.push("/")
28+
throw createError({ statusCode: 404, statusMessage: `Validator ${route.params.id} not found` })
3029
}
3130
3231
defineOgImageComponent("ValidatorImage", {

0 commit comments

Comments
 (0)