mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 12:45:47 +00:00
feat: internal server error page
This commit is contained in:
@@ -279,54 +279,34 @@ func (api *API) SetupRoutes() {
|
|||||||
|
|
||||||
bindErr := c.BindUri(&providerName)
|
bindErr := c.BindUri(&providerName)
|
||||||
|
|
||||||
if bindErr != nil {
|
if handleApiError(c, "Failed to bind URI", bindErr) {
|
||||||
log.Error().Err(bindErr).Msg("Failed to bind URI")
|
|
||||||
c.JSON(400, gin.H{
|
|
||||||
"status": 400,
|
|
||||||
"message": "Bad Request",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
code := c.Query("code")
|
code := c.Query("code")
|
||||||
|
|
||||||
if code == "" {
|
if code == "" {
|
||||||
c.JSON(400, gin.H{
|
log.Error().Msg("No code provided")
|
||||||
"status": 400,
|
c.Redirect(http.StatusPermanentRedirect, "/error")
|
||||||
"message": "Bad Request",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
provider := api.Providers.GetProvider(providerName.Provider)
|
provider := api.Providers.GetProvider(providerName.Provider)
|
||||||
|
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
c.JSON(404, gin.H{
|
c.Redirect(http.StatusPermanentRedirect, "/not-found")
|
||||||
"status": 404,
|
|
||||||
"message": "Not Found",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
token, tokenErr := provider.ExchangeToken(code)
|
token, tokenErr := provider.ExchangeToken(code)
|
||||||
|
|
||||||
if tokenErr != nil {
|
if handleApiError(c, "Failed to exchange token", tokenErr) {
|
||||||
log.Error().Err(tokenErr).Msg("Failed to exchange token")
|
|
||||||
c.JSON(500, gin.H{
|
|
||||||
"status": 500,
|
|
||||||
"message": "Internal Server Error",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
email, emailErr := api.Providers.GetUser(providerName.Provider)
|
email, emailErr := api.Providers.GetUser(providerName.Provider)
|
||||||
|
|
||||||
if emailErr != nil {
|
if handleApiError(c, "Failed to get user", emailErr) {
|
||||||
log.Error().Err(emailErr).Msg("Failed to get user")
|
|
||||||
c.JSON(500, gin.H{
|
|
||||||
"status": 500,
|
|
||||||
"message": "Internal Server Error",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,12 +315,7 @@ func (api *API) SetupRoutes() {
|
|||||||
unauthorizedQuery, unauthorizedQueryErr := query.Values(types.UnauthorizedQuery{
|
unauthorizedQuery, unauthorizedQueryErr := query.Values(types.UnauthorizedQuery{
|
||||||
Email: email,
|
Email: email,
|
||||||
})
|
})
|
||||||
if unauthorizedQueryErr != nil {
|
if handleApiError(c, "Failed to build query", unauthorizedQueryErr) {
|
||||||
log.Error().Err(unauthorizedQueryErr).Msg("Failed to build query")
|
|
||||||
c.JSON(501, gin.H{
|
|
||||||
"status": 501,
|
|
||||||
"message": "Internal Server Error",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Redirect(http.StatusPermanentRedirect, fmt.Sprintf("%s/unauthorized?%s", api.Config.AppURL, unauthorizedQuery.Encode()))
|
c.Redirect(http.StatusPermanentRedirect, fmt.Sprintf("%s/unauthorized?%s", api.Config.AppURL, unauthorizedQuery.Encode()))
|
||||||
@@ -365,12 +340,7 @@ func (api *API) SetupRoutes() {
|
|||||||
RedirectURI: redirectURI,
|
RedirectURI: redirectURI,
|
||||||
})
|
})
|
||||||
|
|
||||||
if redirectQueryErr != nil {
|
if handleApiError(c, "Failed to build query", redirectQueryErr) {
|
||||||
log.Error().Err(redirectQueryErr).Msg("Failed to build query")
|
|
||||||
c.JSON(501, gin.H{
|
|
||||||
"status": 501,
|
|
||||||
"message": "Internal Server Error",
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,3 +376,12 @@ func zerolog() gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleApiError(c *gin.Context, msg string, err error) bool {
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg(msg)
|
||||||
|
c.Redirect(http.StatusPermanentRedirect, "/error")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { LogoutPage } from "./pages/logout-page.tsx";
|
|||||||
import { ContinuePage } from "./pages/continue-page.tsx";
|
import { ContinuePage } from "./pages/continue-page.tsx";
|
||||||
import { NotFoundPage } from "./pages/not-found-page.tsx";
|
import { NotFoundPage } from "./pages/not-found-page.tsx";
|
||||||
import { UnauthorizedPage } from "./pages/unauthorized-page.tsx";
|
import { UnauthorizedPage } from "./pages/unauthorized-page.tsx";
|
||||||
|
import { InternalServerError } from "./pages/internal-server-error.tsx";
|
||||||
|
|
||||||
const queryClient = new QueryClient({
|
const queryClient = new QueryClient({
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
@@ -36,6 +37,7 @@ createRoot(document.getElementById("root")!).render(
|
|||||||
<Route path="/logout" element={<LogoutPage />} />
|
<Route path="/logout" element={<LogoutPage />} />
|
||||||
<Route path="/continue" element={<ContinuePage />} />
|
<Route path="/continue" element={<ContinuePage />} />
|
||||||
<Route path="/unauthorized" element={<UnauthorizedPage />} />
|
<Route path="/unauthorized" element={<UnauthorizedPage />} />
|
||||||
|
<Route path="/error" element={<InternalServerError />} />
|
||||||
<Route path="*" element={<NotFoundPage />} />
|
<Route path="*" element={<NotFoundPage />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
|
|||||||
21
site/src/pages/internal-server-error.tsx
Normal file
21
site/src/pages/internal-server-error.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { Button, Paper, Text } from "@mantine/core";
|
||||||
|
import { Layout } from "../components/layouts/layout";
|
||||||
|
|
||||||
|
export const InternalServerError = () => {
|
||||||
|
return (
|
||||||
|
<Layout>
|
||||||
|
<Paper shadow="md" p={30} mt={30} radius="md" withBorder>
|
||||||
|
<Text size="xl" fw={700}>
|
||||||
|
Internal Server Error
|
||||||
|
</Text>
|
||||||
|
<Text>
|
||||||
|
An error occured on the server and it currently cannot serve your
|
||||||
|
request.
|
||||||
|
</Text>
|
||||||
|
<Button fullWidth mt="xl" onClick={() => window.location.replace("/")}>
|
||||||
|
Try again
|
||||||
|
</Button>
|
||||||
|
</Paper>
|
||||||
|
</Layout>
|
||||||
|
);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user