mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-06 12:47:44 +00:00
* 🪵 Implemented an Improved Global logger solution * 🥈 Removed duplicate APIClient inits * 🐛 Corrected an issue with the payload for spconfig import * 🚤 Significantly improved the Speed of Parsing log files with sail va parse * 🎢 Improved error handling for all VA commands * 💻 Added a VA List Command, along with Get and Set commands for VA Log Config
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package sdk
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
|
|
"github.com/charmbracelet/log"
|
|
)
|
|
|
|
type Message struct {
|
|
Locale string `json:"locale,omitempty"`
|
|
LocaleOrigin string `json:"localeOrigin,omitempty"`
|
|
Text string `json:"text,omitempty"`
|
|
}
|
|
|
|
type SDKResp struct {
|
|
DetailCode string `json:"detailCode,omitempty"`
|
|
TrackingID string `json:"trackingId,omitempty"`
|
|
Messages []Message `json:"messages,omitempty"`
|
|
Causes []interface{} `json:"causes,omitempty"`
|
|
}
|
|
|
|
func HandleSDKError(resp *http.Response, sdkErr error) error {
|
|
defer resp.Body.Close()
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
log.Error(err)
|
|
}
|
|
|
|
var formattedBody SDKResp
|
|
err = json.Unmarshal(body, &formattedBody)
|
|
if err != nil {
|
|
log.Error(err)
|
|
}
|
|
|
|
outputErr := fmt.Sprintf("%s\ndate: %s\nslpt-request-id: %s\nmsgs:\n", sdkErr, resp.Header["Date"][0], resp.Header["Slpt-Request-Id"][0])
|
|
|
|
if len(formattedBody.Messages) > 0 {
|
|
for _, v := range formattedBody.Messages {
|
|
outputErr = outputErr + fmt.Sprintf("%s\n", v.Text)
|
|
}
|
|
} else {
|
|
|
|
}
|
|
|
|
return errors.New(outputErr)
|
|
|
|
}
|