Skip to content

Commit e83be45

Browse files
author
Tien Nam Dao
committed
fix([token]): handle error with API
1 parent 69fa52d commit e83be45

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

pages/token/[token].tsx

+22-13
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ const TokenDetailPage: React.FC<Props> = props => {
2020
const { isMobile } = useMobileLayout()
2121
const { token, tokenData, message } = props
2222

23+
const title = tokenData ? `${tokenData.name} (${tokenData.symbol}) - ${process.env.NEXT_PUBLIC_TITLE}` : token
2324
return (
2425
<Layout>
2526
<Head>
2627
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
27-
<title>
28-
{tokenData.name} ({tokenData.symbol}) - {process.env.NEXT_PUBLIC_TITLE}
29-
</title>
28+
<title>{title}</title>
3029
</Head>
3130
<Container>
3231
<Breadcumbs
@@ -51,21 +50,31 @@ const TokenDetailPage: React.FC<Props> = props => {
5150
export async function getServerSideProps({ params }) {
5251
const { token } = params
5352
if (Web3.utils.isAddress(token, 11115)) {
54-
const tokenData = await evmApi.get<TokenDetailResponse>(`${API_LIST.TOKEN_DETAIL}${token}`)
55-
if (tokenData.data.result) {
53+
try {
54+
const tokenData = await evmApi.get<TokenDetailResponse>(`${API_LIST.TOKEN_DETAIL}${token}`)
55+
if (tokenData.data.result) {
56+
return {
57+
props: {
58+
message: null,
59+
token,
60+
tokenData: tokenData.data.result
61+
}
62+
}
63+
}
5664
return {
5765
props: {
58-
message: null,
66+
message: tokenData.data.message,
5967
token,
60-
tokenData: tokenData.data.result
68+
tokenData: null
6169
}
6270
}
63-
}
64-
return {
65-
props: {
66-
message: tokenData.data.message,
67-
token,
68-
tokenData: null
71+
} catch (err) {
72+
return {
73+
props: {
74+
message: 'Fetch error!',
75+
token,
76+
tokenData: null
77+
}
6978
}
7079
}
7180
}

0 commit comments

Comments
 (0)