51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package requestclient
|
|
|
|
import (
|
|
"jannex/admin-dashboard-backend/modules/config"
|
|
"jannex/admin-dashboard-backend/modules/logger"
|
|
"strconv"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
//const Base = "https://inv.ex.umbach.dev"
|
|
//const ApiBase = Base + "/api"
|
|
|
|
func InvexApiRequestClient(requestMethod string, url string) (statusCode int, body []byte, err error) {
|
|
a := fiber.AcquireAgent()
|
|
|
|
a.Add("Authorization", "Token "+config.Cfg.InvexAPI.Token)
|
|
|
|
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("InvexApiRequestClient err: %s statusCode: %s",
|
|
"invex not authorized", strconv.Itoa(code))
|
|
|
|
return code, nil, err
|
|
}
|
|
|
|
if code == 404 {
|
|
log.Error().Msgf("Invex stock item not found, code: %d", code)
|
|
|
|
logger.AddSystemLog("InvexApiRequestClient err: %s statusCode: %s",
|
|
"invex stock item not found", strconv.Itoa(code))
|
|
|
|
return code, nil, err
|
|
}
|
|
|
|
return code, body, nil
|
|
}
|