From 8d67e318fa1bc6b9e0da220c3a13df5c303e9140 Mon Sep 17 00:00:00 2001 From: Zdenek Devaty Date: Tue, 9 Apr 2024 16:37:34 +0200 Subject: [PATCH] Avoid querying events on root Also, report error on events fetching. --- app.go | 5 ++++- ews/ews.go | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index 981b2ac..036343e 100644 --- a/app.go +++ b/app.go @@ -153,9 +153,12 @@ func collectResources(config apiserver.Configuration) error { if !ast.AssetID.Valid { continue } + if ast.ProviderID == "" { + continue + } appointments, err := ewsHelper.GetRoomAppointments(ast.ProviderID, time.Now().Add(-24*time.Hour), time.Now().Add(7*24*time.Hour)) if err != nil { - log.Error("EWS", "getting appointments: %v", err) + log.Error("EWS", "getting appointments for %s: %v", ast.ProviderID, err) return err } for i := range appointments { diff --git a/ews/ews.go b/ews/ews.go index bb4d947..0569955 100644 --- a/ews/ews.go +++ b/ews/ews.go @@ -185,7 +185,7 @@ func (h *EWSHelper) GetRoomAppointments(roomEmail string, start, end time.Time) - + @@ -201,6 +201,24 @@ func (h *EWSHelper) GetRoomAppointments(roomEmail string, start, end time.Time) if err != nil { return nil, fmt.Errorf("getting room %v appointments: %v", roomEmail, err) } + + // First, try to unmarshal into SOAPFault to see if there was an error. + var soapFault struct { + Body struct { + Fault struct { + FaultCode string `xml:"faultcode"` + FaultString string `xml:"faultstring"` + Detail struct { + ResponseCode string `xml:"ResponseCode"` + Message string `xml:"Message"` + } `xml:"detail"` + } `xml:"Fault"` + } `xml:"Body"` + } + if err := xml.Unmarshal([]byte(responseXML), &soapFault); err == nil && soapFault.Body.Fault.FaultCode != "" { + return nil, fmt.Errorf("SOAP fault: %s - %s", soapFault.Body.Fault.Detail.ResponseCode, soapFault.Body.Fault.Detail.Message) + } + var env roomEventsEnvelope if err := xml.Unmarshal([]byte(responseXML), &env); err != nil { return nil, fmt.Errorf("unmarshaling XML: %v", err)