/
errorMessage.go
48 lines (39 loc) · 1016 Bytes
/
errorMessage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package helper
import (
// "fmt"
"github.com/labstack/echo"
"github.com/nguyencatpham/go-effective-study/pkg/utl/config"
"github.com/thoas/go-funk"
)
var appConfig *config.Configuration
func SetAppConfig(data *config.Configuration) {
appConfig = data
}
func GetAppConfig() *config.Configuration {
return appConfig
}
var errorDict *config.ErrorDict
func SetErrorList(data *config.ErrorDict) {
errorDict = data
}
func GetError(status int, messageType string) error {
var err = echo.NewHTTPError(status, "problem to perform your action")
if errorDict != nil {
if errorDict.ErrorList != nil && len(errorDict.ErrorList) > 0 {
temp := funk.Find(errorDict.ErrorList, func(item config.ErrorMessage) bool {
if item.Type == messageType {
return true
}
return false
})
if temp != nil {
temp := temp.(config.ErrorMessage)
err = echo.NewHTTPError(status, temp.Text)
}
}
}
return err
}
func HandleError(message string) error {
return echo.NewHTTPError(400, message)
}