Skip to content

Commit

Permalink
fix: increse email timeout and handle error better
Browse files Browse the repository at this point in the history
fixes #7
  • Loading branch information
scottmckendry committed Feb 7, 2024
1 parent 5d5e004 commit b897abf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 5 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"log"
"os"
"strconv"
"time"
Expand Down Expand Up @@ -169,7 +170,10 @@ func handleSendInvoice(c *fiber.Ctx) error {
}
err = sendInvoice(id)
if err != nil {
return c.Status(500).SendString(err.Error())
log.Println(err)
// We're intentionally not returning the error to the client here. HTMX won't update the element if the response is an error.
// Not sure why this is the case, but probably worth revisiting in the future.
return c.SendString("Failed :(")
}
return c.SendString("Done!")
}
1 change: 1 addition & 0 deletions invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func sendEmail(dog Dog) error {
os.Getenv("SMTP_USER"),
os.Getenv("SMTP_PASS"),
)
d.Timeout = 30 * time.Second
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}

ownerFirstName := strings.Split(dog.OwnerName, " ")[0]
Expand Down
2 changes: 2 additions & 0 deletions views/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ <h2>{{ .Name }}</h2>
class="btn-primary"
hx-post="/invoice/{{.ID}}"
hx-indicator="#spinner"
hx-swap="innerHTML"
hx-target="this"
href=""
>
Send
Expand Down
6 changes: 1 addition & 5 deletions views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
href="https://www.nerdfonts.com/assets/css/webfont.css"
rel="stylesheet"
/>
<script
src="https://unpkg.com/[email protected]"
integrity="sha384-FhXw7b6AlE/jyjlZH5iHa/tTe9EpJ1Y55RjcgPbjeWMskSxZt1v9qkxLJWNJaGni"
crossorigin="anonymous"
></script>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/[email protected]"></script>
</head>
<body>
Expand Down

0 comments on commit b897abf

Please sign in to comment.