More changes
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 26s

This commit is contained in:
2025-06-01 17:05:38 -04:00
parent 38d884e450
commit ded46bb720
3 changed files with 67 additions and 56 deletions

108
client.go
View File

@ -268,24 +268,61 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
c.logger.Error("error while getting body", "error", err.Error())
}
var r Response
err = json.Unmarshal(resBytes, &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)
if r, ok := c.parseResponse(resBytes); ok {
c.logger.Debug("parsed 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())
}
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())
}
if pollingUrl != "" {
time.Sleep(3 * time.Second)
attempts := 20
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--
time.Sleep(3 * time.Second)
}
}
// for {
// if attempt >= attempts {
// break
@ -313,47 +350,6 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str
// }
// attempt++
// }
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--
time.Sleep(3 * time.Second)
}
}
} else {
c.logger.Error("request is not successfull", "request", "execute", "method", method, "url", requestUrl, "error", err.Error())