Skip to content

Commit

Permalink
Avoid querying events on root
Browse files Browse the repository at this point in the history
Also, report error on events fetching.
  • Loading branch information
zdevaty committed Apr 10, 2024
1 parent c6c3913 commit 8d67e31
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 19 additions & 1 deletion ews/ews.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (h *EWSHelper) GetRoomAppointments(roomEmail string, start, end time.Time)
<t:FieldURI FieldURI="calendar:IsCancelled"/>
</t:AdditionalProperties>
</m:ItemShape>
<m:CalendarView MaxEntriesReturned="50" StartDate="%s" EndDate="%s"/>
<m:CalendarView MaxEntriesReturned="65536" StartDate="%s" EndDate="%s"/>
<m:ParentFolderIds>
<t:DistinguishedFolderId Id="calendar">
<t:Mailbox>
Expand All @@ -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)
Expand Down

0 comments on commit 8d67e31

Please sign in to comment.