Skip to content

Commit

Permalink
update xml error parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMoonThatRises committed Aug 16, 2024
1 parent f31504e commit 48dcc16
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Sources/StudentVue/Extensions/XMLHash+parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Foundation
import SWXMLHash

public extension XMLHash {
static fileprivate let errorAttributes = ["ERROR_MESSAGE", "errorMessage"]

/// Wrapper of XMLHash parse function
///
/// - Parameter soapString: The SOAP XML to parse
Expand All @@ -20,11 +22,23 @@ public extension XMLHash {
let request = parse(soapString)["soap:Envelope"]["soap:Body"]["ProcessWebServiceRequestResponse"]["ProcessWebServiceRequestResult"]

do {
throw StudentVueApi.StudentVueErrors.soapError(try request["RT_ERROR"].value(ofAttribute: "ERROR_MESSAGE"))
for child in request.children {
for attr in XMLHash.errorAttributes {
do {
guard let attrValue = child.element?.attribute(by: attr)?.text else {
continue
}

throw StudentVueApi.StudentVueErrors.soapError(attrValue)
} catch let error as StudentVueApi.StudentVueErrors {
throw error
}
}
}
} catch let error as StudentVueApi.StudentVueErrors {
throw error
} catch {
return request
}

return request
}
}

0 comments on commit 48dcc16

Please sign in to comment.