virtual-vehicle: add debug logging
This commit is contained in:
@@ -42,6 +42,7 @@ func main() {
|
||||
cert, key, err := registerVehicle(vin)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("Failed to register vehicle")
|
||||
time.Sleep(time.Second) // Allow log to flush
|
||||
os.Exit(1)
|
||||
}
|
||||
logger.Info().Str("vin", vin).Msg("Vehicle registered successfully")
|
||||
@@ -98,21 +99,29 @@ func registerVehicle(vin string) (cert, key string, err error) {
|
||||
payload := map[string]string{"vin": vin}
|
||||
body, _ := json.Marshal(payload)
|
||||
|
||||
logger.Debug().Str("payload", string(body)).Msg("Creating request")
|
||||
|
||||
req, err := http.NewRequest("POST", manufacturerURL, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", "", fmt.Errorf("create request: %w", err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
if apiKey != "" {
|
||||
req.Header.Set("Api-Key", apiKey)
|
||||
logger.Debug().Msg("API key set")
|
||||
} else {
|
||||
logger.Warn().Msg("No API key configured")
|
||||
}
|
||||
|
||||
logger.Debug().Msg("Sending HTTP request")
|
||||
client := &http.Client{Timeout: 30 * time.Second}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", "", fmt.Errorf("http request: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
logger.Debug().Int("status", resp.StatusCode).Msg("Got response")
|
||||
|
||||
if resp.StatusCode >= 300 {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
|
||||
Reference in New Issue
Block a user