Skip to content

Commit

Permalink
Add error message redaction method (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroFish91 authored Oct 10, 2024
1 parent 1682083 commit 883bd84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions api/utils/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package utils

import "regexp"

func redactError(err string) string {
switch {
case regexp.MustCompile(`(?i)failed[\s]to[\s]connect`).Match([]byte(err)) ||
regexp.MustCompile(`(?i)connection[\s]refused`).Match([]byte(err)):
return "internal error: could not connect to requisite database service"
default:
return err
}
}
2 changes: 1 addition & 1 deletion api/utils/send_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func SendError(c fiber.Ctx, status int, e error) error {
c.Response().Header.SetContentType("application/json")
err := c.Status(status).JSON(fiber.Map{
"status": status,
"error": e.Error(),
"error": redactError(e.Error()),
})

if err != nil {
Expand Down

0 comments on commit 883bd84

Please sign in to comment.