Improved error handling
This commit is contained in:
parent
1263e66f45
commit
5944b7253d
16
main.go
16
main.go
|
@ -30,6 +30,22 @@ func main() {
|
|||
Prefork: utils.Config["fiberPrefork"].(bool),
|
||||
UnescapePath: true,
|
||||
StreamRequestBody: true,
|
||||
ErrorHandler: func(ctx *fiber.Ctx, err error) error {
|
||||
code := fiber.StatusInternalServerError
|
||||
|
||||
if e, ok := err.(*fiber.Error); ok {
|
||||
code = e.Code
|
||||
}
|
||||
|
||||
err = ctx.Status(code).Render("errors/error", fiber.Map{
|
||||
"err": err,
|
||||
})
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
app.Use(recover.New(recover.Config{
|
||||
|
|
|
@ -25,7 +25,7 @@ func HandleEmbed(c *fiber.Ctx) error {
|
|||
if err != nil && err.Error() == "ratelimited by imgur" {
|
||||
return c.Status(429).Render("errors/429", nil)
|
||||
}
|
||||
if post.Id == "" || (err != nil && strings.Contains(err.Error(), "404")) {
|
||||
if err != nil && post.Id == "" && strings.Contains(err.Error(), "404") {
|
||||
return c.Status(404).Render("errors/404", nil)
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
@ -26,10 +26,10 @@ func HandlePost(c *fiber.Ctx) error {
|
|||
if err != nil && err.Error() == "ratelimited by imgur" {
|
||||
return c.Status(429).Render("errors/429", nil)
|
||||
}
|
||||
if post.Id == "" || (err != nil && strings.Contains(err.Error(), "404")) {
|
||||
if err != nil && post.Id == "" && strings.Contains(err.Error(), "404") {
|
||||
return c.Status(404).Render("errors/404", nil)
|
||||
}
|
||||
if err != nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
h2, p {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
main {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
code {
|
||||
display: block;
|
||||
padding: 0.5em;
|
||||
background-color: #383838;
|
||||
width: 50%;
|
||||
margin: 0.5em auto;
|
||||
word-wrap: break-word;
|
||||
border-radius: 4px;
|
||||
font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace;
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
{{> 'partials/head' }}
|
||||
|
||||
<title>404 - rimgo</title>
|
||||
<title>404 Not Found - rimgo</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
{{> 'partials/head' }}
|
||||
|
||||
<title>404 - rimgo</title>
|
||||
<title>Rate limited by Imgur - rimgo</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
{{> 'partials/head' }}
|
||||
|
||||
<link rel="stylesheet" href="/static/css/error.css" />
|
||||
|
||||
<title>Error - rimgo</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{{> 'partials/header' }}
|
||||
|
||||
<main>
|
||||
<h2 class="errorTitle">An error occurred</h2>
|
||||
<p>You may have found a bug in rimgo. If this is a bug, open an issue on <a href="https://codeberg.org/video-prize-ranch/rimgo/issues/new">Codeberg</a>.</p>
|
||||
<code>{{err}}</code>
|
||||
</main>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue