63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package requestclient
|
|
|
|
import (
|
|
"jannex/admin-dashboard-backend/modules/logger"
|
|
"jannex/admin-dashboard-backend/modules/structs"
|
|
"jannex/admin-dashboard-backend/modules/utils"
|
|
"strconv"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
const Base = "https://inv.ex.umbach.dev"
|
|
const ApiBase = Base + "/api"
|
|
const ApiToken = "1367f15d21935e4eb540f897946fb5cd98485c3f"
|
|
|
|
func InvexApiRequestClient(requestMethod string, url string) (statusCode int, body []byte, err error) {
|
|
a := fiber.AcquireAgent()
|
|
|
|
a.Add("Authorization", "Token "+ApiToken)
|
|
|
|
req := a.Request()
|
|
req.Header.SetMethod(requestMethod)
|
|
req.SetRequestURI(url)
|
|
|
|
if err := a.Parse(); err != nil {
|
|
log.Error().Msgf("Failed to parse request, err: %s", err)
|
|
return 0, nil, err
|
|
}
|
|
|
|
code, body, _ := a.Bytes()
|
|
|
|
if code == 401 {
|
|
log.Error().Msgf("invex not authorized, code: %d", code)
|
|
|
|
logger.AddSystemLog(structs.LogMessage{
|
|
Id: 29,
|
|
Type: utils.LogTypeInfo,
|
|
Messages: []structs.LogData{
|
|
{Type: "error", Value: "invex not authorized"},
|
|
{Type: "statusCode", Value: strconv.Itoa(code)},
|
|
},
|
|
})
|
|
|
|
return code, nil, err
|
|
}
|
|
|
|
if code == 404 {
|
|
log.Error().Msgf("Invex stock item not found, code: %d", code)
|
|
|
|
logger.AddSystemLog(structs.LogMessage{
|
|
Id: 29,
|
|
Type: utils.LogTypeInfo,
|
|
Messages: []structs.LogData{
|
|
{Type: "error", Value: "invex stock item not found"},
|
|
{Type: "statusCode", Value: strconv.Itoa(code)},
|
|
},
|
|
})
|
|
return code, nil, err
|
|
}
|
|
|
|
return code, body, nil
|
|
} |