Skip to content

Commit 33877ee

Browse files
committed
chore: Changed the way error handling
1 parent d403129 commit 33877ee

File tree

5 files changed

+38
-48
lines changed

5 files changed

+38
-48
lines changed

app/models/licence.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package models
2+
3+
type Licence struct {
4+
ID string `json:"id"`
5+
Data string `json:"data"`
6+
ExtensionID string `json:"extension_id"`
7+
CreatedAt string `json:"created_at"`
8+
UpdatedAt string `json:"updated_at"`
9+
}
10+
11+
func (Licence) TableName() string {
12+
return "licenses"
13+
}

internal/liman/auth.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package liman
22

33
import (
4-
"errors"
5-
4+
"github.com/gofiber/fiber/v2"
65
"github.com/limanmys/render-engine/app/models"
76
"github.com/limanmys/render-engine/internal/database"
87
)
@@ -13,7 +12,7 @@ func AuthWithToken(token string) (string, error) {
1312
err := database.Connection().First(&tokenObj, "token = ?", token).Error
1413

1514
if err != nil || len(tokenObj.UserID) < 1 {
16-
return "", errors.New("Authorization token is not valid.")
15+
return "", fiber.NewError(fiber.StatusUnauthorized, "Authorization token is not valid.")
1716
}
1817

1918
return tokenObj.UserID, nil
@@ -25,7 +24,7 @@ func AuthWithAccessToken(token string) (string, error) {
2524
err := database.Connection().First(&tokenObj, "token = ?", token).Error
2625

2726
if err != nil || len(tokenObj.UserID) < 1 {
28-
return "", errors.New("Authorization token is not valid.")
27+
return "", fiber.NewError(fiber.StatusUnauthorized, "Authorization token is not valid.")
2928
}
3029

3130
return tokenObj.UserID, nil

internal/liman/role_system.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package liman

internal/liman/user.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package liman
2+
3+
import (
4+
"github.com/gofiber/fiber/v2"
5+
"github.com/limanmys/render-engine/app/models"
6+
"github.com/limanmys/render-engine/internal/database"
7+
)
8+
9+
func GetUser(user *models.User) (*models.User, error) {
10+
result := database.Connection().First(&user)
11+
12+
if result.Error != nil {
13+
return nil, fiber.NewError(fiber.StatusNotFound, "Cannot found user with this id")
14+
}
15+
16+
if result.RowsAffected > 0 {
17+
return user, nil
18+
}
19+
20+
return nil, fiber.NewError(fiber.StatusNotFound, "Cannot found user with this id")
21+
}

internal/middleware/auth.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)