Refactor service request execution to improve error handling and remove unused message simulation
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 28s
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 28s
This commit is contained in:
35
vehicle.go
35
vehicle.go
@ -473,23 +473,6 @@ func (v *Vehicle) GetLocation(force bool) (chan string, error) {
|
||||
reqUrl = MOBILE_API_VERSION + urlToGen(apiURLs["API_LOCATE"], v.getAPIGen())
|
||||
}
|
||||
|
||||
// Simulate sending multiple messages to the channel
|
||||
// go func() {
|
||||
// defer close(msgChan) // Close the channel when the goroutine finishes
|
||||
|
||||
// for i := 1; i <= numMessages; i++ {
|
||||
// // Simulate some work or delay before sending the message
|
||||
// time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// msg := Message{
|
||||
// Content: fmt.Sprintf("Message %d", i),
|
||||
// Success: true, // Indicate success for each message
|
||||
// }
|
||||
// msgChan <- msg
|
||||
// fmt.Printf("Sent: %s (Success: %t)\n", msg.Content, msg.Success)
|
||||
// }
|
||||
// }()
|
||||
|
||||
ch := make(chan string)
|
||||
go func() {
|
||||
defer close(ch)
|
||||
@ -511,18 +494,24 @@ func (v *Vehicle) executeServiceRequest(params map[string]string, reqUrl, pollin
|
||||
if v.Vin != v.client.currentVin {
|
||||
v.selectVehicle()
|
||||
}
|
||||
var url string
|
||||
|
||||
var resp *Response
|
||||
var err error
|
||||
if attempt == 1 {
|
||||
url = reqUrl
|
||||
} else {
|
||||
url = pollingUrl
|
||||
}
|
||||
resp, err := v.client.execute(POST, url, params, true)
|
||||
resp, err = v.client.execute(POST, reqUrl, params, true)
|
||||
if err != nil {
|
||||
v.client.logger.Error("error while executing service request", "request", reqUrl, "error", err.Error())
|
||||
ch <- "error"
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
resp, err = v.client.execute(GET, pollingUrl, params, false)
|
||||
if err != nil {
|
||||
v.client.logger.Error("error while executing service request status polling", "request", reqUrl, "error", err.Error())
|
||||
ch <- "error"
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// dataName field has the list of the states [ remoteServiceStatus | errorResponse ]
|
||||
if resp.DataName == "remoteServiceStatus" {
|
||||
|
Reference in New Issue
Block a user