Skip to content

Commit

Permalink
Check 500 instead of 502, 502-503 can come from LB also
Browse files Browse the repository at this point in the history
  • Loading branch information
KostLinux committed Apr 19, 2024
1 parent e55b453 commit 5bc2413
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
42 changes: 21 additions & 21 deletions controller/error/http_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ func StatusNotFound(c *gin.Context) {
}
}

// Show 502 Bad Gateway error page
func StatusBadGateway() gin.HandlerFunc {
return func(c *gin.Context) {
defer func() {
if request := recover(); request != nil {
c.Status(http.StatusBadGateway)
file, err := os.Open("./public/error/502.html")
if err != nil {
log.Printf("Error opening file: %v", err)
return
}
defer file.Close()
if _, err := io.Copy(c.Writer, file); err != nil {
if err := c.Error(err); err != nil {
log.Printf("Error adding error to Gin context: %v", err)
}
}
}
}()
c.Next()
}
// Show 500 Internal Server Error page
func StatusInternalServerError() gin.HandlerFunc {
return func(c *gin.Context) {

Check failure on line 30 in controller/error/http_errors.go

View workflow job for this annotation

GitHub Actions / Verify Backend Code Quality

File is not `gofmt`-ed with `-s` (gofmt)
defer func() {
if request := recover(); request != nil {
c.Status(http.StatusInternalServerError)
file, err := os.Open("./public/error/500.html")
if err != nil {
log.Printf("Error opening file: %v", err)
return
}
defer file.Close()
if _, err := io.Copy(c.Writer, file); err != nil {
if err := c.Error(err); err != nil {
log.Printf("Error adding error to Gin context: %v", err)
}
}
}
}()
c.Next()
}
}
4 changes: 2 additions & 2 deletions public/error/502.html → public/error/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</head>
<body class="bg-gray-200 flex items-center justify-center h-screen">
<div class="text-center">
<h1 class="text-6xl font-bold text-gray-700 mb-4">502</h1>
<h2 class="text-4xl text-gray-500 mb-8">Bad Gateway</h2>
<h1 class="text-6xl font-bold text-gray-700 mb-4">500</h1>
<h2 class="text-4xl text-gray-500 mb-8">Internal Server Error</h2>
<p class="text-gray-500 mb-8">The server encountered a temporary error and could not complete your request.</p>
<a href="/" class="inline-block text-white bg-indigo-500 px-6 py-3 border border-transparent rounded-md font-medium hover:bg-indigo-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Go Home</a> </div>
</body>
Expand Down

0 comments on commit 5bc2413

Please sign in to comment.