More changes
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 26s
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 26s
This commit is contained in:
128
client.go
128
client.go
@ -236,7 +236,6 @@ func (c *Client) GetVehicleByVIN(vin string) *Vehicle {
|
||||
// Exec method executes a Client instance with the API URL
|
||||
func (c *Client) execute(requestUrl string, method string, params map[string]string, pollingUrl string, j bool) []byte {
|
||||
defer timeTrack("[TIMETRK] Executing Get Request")
|
||||
|
||||
var resp *resty.Response
|
||||
|
||||
// GET Requests
|
||||
@ -249,14 +248,12 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
||||
|
||||
// POST Requests
|
||||
if method == "POST" {
|
||||
if j {
|
||||
// POST > JSON Body
|
||||
if j { // POST > JSON Body
|
||||
resp, _ = c.httpClient.
|
||||
R().
|
||||
SetBody(params).
|
||||
Post(requestUrl)
|
||||
} else {
|
||||
// POST > Form Data
|
||||
} else { // POST > Form Data
|
||||
resp, _ = c.httpClient.
|
||||
R().
|
||||
SetFormData(params).
|
||||
@ -271,84 +268,77 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
|
||||
if r, ok := c.parseResponse(resBytes); ok {
|
||||
c.logger.Debug("parsed http request output", "data", r.Data)
|
||||
|
||||
// dataName field has the list of the states [ remoteServiceStatus | errorResponse ]
|
||||
if r.DataName == "remoteServiceStatus" {
|
||||
var sr ServiceRequest
|
||||
err := json.Unmarshal(r.Data, &sr)
|
||||
if err != nil {
|
||||
c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
||||
}
|
||||
// {"success":false,"errorCode":"404-soa-unableToParseResponseBody","dataName":"errorResponse","data":{"errorLabel":"404-soa-unableToParseResponseBody","errorDescription":null}}
|
||||
|
||||
if pollingUrl != "" {
|
||||
time.Sleep(3 * time.Second)
|
||||
attempts := 20
|
||||
|
||||
poolingLoop:
|
||||
for attempts > 0 {
|
||||
resp, _ = c.httpClient.
|
||||
SetBaseURL(MOBILE_API_SERVER[c.country]).
|
||||
R().
|
||||
SetQueryParams(map[string]string{
|
||||
"serviceRequestId": sr.ServiceRequestID,
|
||||
}).
|
||||
Get(pollingUrl)
|
||||
resBytes, _ := io.ReadAll(resp.Body)
|
||||
c.logger.Debug("POLLING HTTP OUTPUT", "body", string(resBytes))
|
||||
// {"success":false,"errorCode":"404-soa-unableToParseResponseBody","dataName":"errorResponse","data":{"errorLabel":"404-soa-unableToParseResponseBody","errorDescription":null}}
|
||||
|
||||
var r Response
|
||||
err := json.Unmarshal(resBytes, &r)
|
||||
if err != nil {
|
||||
c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
||||
}
|
||||
c.logger.Debug("parsed loop http request output", "request", "HTTP POLLING", "data", r.Data)
|
||||
|
||||
if r.Success {
|
||||
var sr ServiceRequest
|
||||
err := json.Unmarshal(r.Data, &sr)
|
||||
if err != nil {
|
||||
c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
||||
}
|
||||
switch {
|
||||
case sr.RemoteServiceState == "finished":
|
||||
c.logger.Debug("Remote service request completed successfully", "request id", sr.ServiceRequestID)
|
||||
break poolingLoop
|
||||
case sr.RemoteServiceState == "started":
|
||||
c.logger.Debug("Subaru API reports remote service request is in progress", "request id", sr.ServiceRequestID)
|
||||
}
|
||||
} else {
|
||||
c.logger.Debug("Backend session expired, please try again")
|
||||
break poolingLoop
|
||||
}
|
||||
attempts--
|
||||
switch {
|
||||
case sr.RemoteServiceState == "finished":
|
||||
// Finished RemoteServiceState Service Request does not include Service Request ID
|
||||
c.logger.Debug("Remote service request completed successfully")
|
||||
case sr.RemoteServiceState == "started":
|
||||
time.Sleep(3 * time.Second)
|
||||
c.logger.Debug("Subaru API reports remote service request (started) is in progress", "id", sr.ServiceRequestID)
|
||||
c.execute(pollingUrl, GET, map[string]string{"serviceRequestId": sr.ServiceRequestID}, pollingUrl, false)
|
||||
case sr.RemoteServiceState == "stopping":
|
||||
time.Sleep(3 * time.Second)
|
||||
c.logger.Debug("Subaru API reports remote service request (stopping) is in progress", "id", sr.ServiceRequestID)
|
||||
c.execute(pollingUrl, GET, map[string]string{"serviceRequestId": sr.ServiceRequestID}, pollingUrl, false)
|
||||
default:
|
||||
time.Sleep(3 * time.Second)
|
||||
c.logger.Debug("Subaru API reports remote service request (stopping) is in progress")
|
||||
c.execute(pollingUrl, GET, map[string]string{"serviceRequestId": sr.ServiceRequestID}, pollingUrl, false)
|
||||
}
|
||||
}
|
||||
// for {
|
||||
// if attempt >= attempts {
|
||||
// break
|
||||
// }
|
||||
// resp := c.execute(pollingUrl, GET, map[string]string{"serviceRequestId": sr.ServiceRequestID}, pollingUrl, false)
|
||||
// var r Response
|
||||
// err = json.Unmarshal(resp, &r)
|
||||
// if err != nil {
|
||||
// c.logger.Error("error while parsing json", "request", "execute", "method", method, "url", requestUrl, "error", err.Error())
|
||||
// }
|
||||
// c.logger.Debug("parsed http request output", "request", "HTTP POLLING", "data", r.Data)
|
||||
|
||||
// var sr ServiceRequest
|
||||
// err := json.Unmarshal(r.Data, &sr)
|
||||
// if err != nil {
|
||||
// c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
||||
// }
|
||||
// if pollingUrl != "" {
|
||||
// time.Sleep(3 * time.Second)
|
||||
// attempts := 20
|
||||
|
||||
// switch {
|
||||
// case sr.RemoteServiceState == "finished":
|
||||
// c.logger.Debug("Remote service request completed successfully", "request id", sr.ServiceRequestID)
|
||||
// break
|
||||
// case sr.RemoteServiceState == "started":
|
||||
// c.logger.Debug("Subaru API reports remote service request is in progress", "request id", sr.ServiceRequestID)
|
||||
// poolingLoop:
|
||||
// for attempts > 0 {
|
||||
// resp, _ = c.httpClient.
|
||||
// R().
|
||||
// SetQueryParams(map[string]string{
|
||||
// "serviceRequestId": sr.ServiceRequestID,
|
||||
// }).
|
||||
// Get(pollingUrl)
|
||||
// resBytes, _ := io.ReadAll(resp.Body)
|
||||
// c.logger.Debug("POLLING HTTP OUTPUT", "body", string(resBytes))
|
||||
|
||||
// var r Response
|
||||
// err := json.Unmarshal(resBytes, &r)
|
||||
// if err != nil {
|
||||
// c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
||||
// }
|
||||
// c.logger.Debug("parsed loop http request output", "request", "HTTP POLLING", "data", r.Data)
|
||||
|
||||
// if r.Success {
|
||||
// var sr ServiceRequest
|
||||
// err := json.Unmarshal(r.Data, &sr)
|
||||
// if err != nil {
|
||||
// c.logger.Error("error while parsing json", "request", "HTTP POLLING", "error", err.Error())
|
||||
// }
|
||||
// switch {
|
||||
// case sr.RemoteServiceState == "finished":
|
||||
// c.logger.Debug("Remote service request completed successfully", "request id", sr.ServiceRequestID)
|
||||
// break poolingLoop
|
||||
// case sr.RemoteServiceState == "started":
|
||||
// c.logger.Debug("Subaru API reports remote service request is in progress", "request id", sr.ServiceRequestID)
|
||||
// }
|
||||
// } else {
|
||||
// c.logger.Debug("Backend session expired, please try again")
|
||||
// break poolingLoop
|
||||
// }
|
||||
// attempts--
|
||||
// time.Sleep(3 * time.Second)
|
||||
// }
|
||||
// attempt++
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user