Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added custom error pages 500,503,403 #437

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/pages/403.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useEffect, useState } from "react"
import { navigate } from "gatsby"

import Layout from "../components/layout"
import SEO from "../components/seo"

const ForbiddenPage = () => {
const [second, setSecond] = useState(6)
function manageTime() {
setSecond(second => second - 1)
if (second >= 0) {
setTimeout(manageTime, 1000)
}
}

useEffect(() => {
setTimeout(manageTime, 0)

setTimeout(() => {
navigate("/")
}, 5000)
}, [])

return (
<Layout>
<SEO title="403: Forbidden" />
<h1>FORBIDDEN</h1>
<p>
You are not authorized to access this resource. You are being redirected to
the homepage in {second}s.
</p>
</Layout>
)
}

export default ForbiddenPage
36 changes: 36 additions & 0 deletions src/pages/500.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useEffect, useState } from "react"
import { navigate } from "gatsby"

import Layout from "../components/layout"
import SEO from "../components/seo"

const InternalServerErrorPage = () => {
const [second, setSecond] = useState(6)
function manageTime() {
setSecond(second => second - 1)
if (second >= 0) {
setTimeout(manageTime, 1000)
}
}

useEffect(() => {
setTimeout(manageTime, 0)

setTimeout(() => {
navigate("/")
}, 5000)
}, [])

return (
<Layout>
<SEO title="500: Internal Server Error" />
<h1>INTERNAL SERVER ERROR</h1>
<p>
An unexpected error occurred on the server. We apologize for the
inconvenience. You are being redirected to the homepage in {second}s.
</p>
</Layout>
)
}

export default InternalServerErrorPage
36 changes: 36 additions & 0 deletions src/pages/503.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useEffect, useState } from "react"
import { navigate } from "gatsby"

import Layout from "../components/layout"
import SEO from "../components/seo"

const ServiceUnavailablePage = () => {
const [second, setSecond] = useState(6)
function manageTime() {
setSecond(second => second - 1)
if (second >= 0) {
setTimeout(manageTime, 1000)
}
}

useEffect(() => {
setTimeout(manageTime, 0)

setTimeout(() => {
navigate("/")
}, 5000)
}, [])

return (
<Layout>
<SEO title="503: Service Unavailable" />
<h1>SERVICE UNAVAILABLE</h1>
<p>
The server is currently unavailable. Please try again later. You are being
redirected to the homepage in {second}s.
</p>
</Layout>
)
}

export default ServiceUnavailablePage
8 changes: 8 additions & 0 deletions static/web.config
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/404" responseMode="ExecuteURL" />
<remove statusCode="500" subStatusCode="-1" />
<!-- <remove statusCode="403" subStatusCode="-1" /> -->
<remove statusCode="503" subStatusCode="-1" />

<!-- Custom error pages for each status code -->
<error statusCode="500" prefixLanguageFilePath="" path="/500.html" responseMode="File" />
<!-- <error statusCode="403" prefixLanguageFilePath="" path="/403.html" responseMode="File" /> -->
<error statusCode="503" prefixLanguageFilePath="" path="/503.html" responseMode="File" />
</httpErrors>
</system.webServer>
</configuration>
Loading