Skip to content

Commit 5d228bd

Browse files
committed
error fix
1 parent c0e4510 commit 5d228bd

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

handlers/auth.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"http-proxy/conf"
55
"http-proxy/models"
66
"http-proxy/utils"
7+
"strings"
78
"time"
89

910
"github.com/dgrijalva/jwt-go"
@@ -21,18 +22,21 @@ func (ah AuthHandler) Authenticate(c *fiber.Ctx) error {
2122
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
2223
"message": err.Error(),
2324
})
24-
2525
}
2626
if err := utils.Validate(body); err != nil {
2727
return c.Status(400).JSON(fiber.Map{
2828
"message": err,
2929
})
30-
3130
}
3231
conn, err := memphis.Connect(configuration.MEMPHIS_HOST, body.Username, body.ConnectionToken)
3332
if err != nil {
33+
if strings.Contains(err.Error(), "Authorization Violation") {
34+
return c.Status(401).JSON(fiber.Map{
35+
"message": "Wrong credentials",
36+
})
37+
}
3438
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
35-
"message": "Wrong credentials",
39+
"message": "Server error",
3640
})
3741
}
3842
conn.Close()
@@ -71,7 +75,6 @@ func createTokens() (string, string, error) {
7175
if err != nil {
7276
return "", "", err
7377
}
74-
7578
return token, refreshToken, nil
7679
}
7780

utils/schema_validation.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ type ValidationError struct {
1414
}
1515

1616
func InitializeValidations() {
17-
1817
Validator = validator.New()
19-
2018
}
2119

2220
func Validate(schema any) []ValidationError {
@@ -31,7 +29,6 @@ func Validate(schema any) []ValidationError {
3129
errors = append(errors, ValidationError{Field: f.Field(), Reason: tErr})
3230
}
3331
return errors
34-
3532
}
3633
return nil
3734
}

0 commit comments

Comments
 (0)