Skip to content

Commit

Permalink
Show 404 page on connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
iAdramelk committed Dec 5, 2019
1 parent 3cf403f commit 1102157
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions pages/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,28 @@ Documentation.getInitialProps = async ({ asPath, req }) => {
const host = req ? req.headers['host'] : window.location.host
const protocol = host.indexOf('localhost') > -1 ? 'http:' : 'https:'

const res = await fetch(`${protocol}//${host}${item.source}`)
try {
const res = await fetch(`${protocol}//${host}${item.source}`)

if (res.status !== 200) {
return {
errorCode: res.status
console.log(res, res.status)

if (res.status !== 200) {
return {
errorCode: res.status
}
}
}

const text = await res.text()
const text = await res.text()

return {
item: item,
headings: parseHeadings(text),
markdown: text
return {
item: item,
headings: parseHeadings(text),
markdown: text
}
} catch (e) {
return {
errorCode: 404
}
}
}

Expand Down

0 comments on commit 1102157

Please sign in to comment.