Skip to content

Commit

Permalink
chore: Changed the way error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Sep 1, 2022
1 parent d403129 commit 33877ee
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 48 deletions.
13 changes: 13 additions & 0 deletions app/models/licence.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package models

type Licence struct {
ID string `json:"id"`
Data string `json:"data"`
ExtensionID string `json:"extension_id"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}

func (Licence) TableName() string {
return "licenses"
}
7 changes: 3 additions & 4 deletions internal/liman/auth.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package liman

import (
"errors"

"github.com/gofiber/fiber/v2"
"github.com/limanmys/render-engine/app/models"
"github.com/limanmys/render-engine/internal/database"
)
Expand All @@ -13,7 +12,7 @@ func AuthWithToken(token string) (string, error) {
err := database.Connection().First(&tokenObj, "token = ?", token).Error

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

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

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

return tokenObj.UserID, nil
Expand Down
1 change: 1 addition & 0 deletions internal/liman/role_system.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package liman
21 changes: 21 additions & 0 deletions internal/liman/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package liman

import (
"github.com/gofiber/fiber/v2"
"github.com/limanmys/render-engine/app/models"
"github.com/limanmys/render-engine/internal/database"
)

func GetUser(user *models.User) (*models.User, error) {
result := database.Connection().First(&user)

if result.Error != nil {
return nil, fiber.NewError(fiber.StatusNotFound, "Cannot found user with this id")
}

if result.RowsAffected > 0 {
return user, nil
}

return nil, fiber.NewError(fiber.StatusNotFound, "Cannot found user with this id")
}
44 changes: 0 additions & 44 deletions internal/middleware/auth.go

This file was deleted.

0 comments on commit 33877ee

Please sign in to comment.