@@ -55,6 +55,10 @@ internal enum RuntimeError: Error, CustomStringConvertible, LocalizedError, Pret
55
55
case transportFailed( any Error )
56
56
case handlerFailed( any Error )
57
57
58
+ // Unexpected response (thrown by shorthand APIs)
59
+ case unexpectedResponseStatus( expectedStatus: String , response: Any )
60
+ case unexpectedResponseBody( expectedContent: String , body: Any )
61
+
58
62
// MARK: CustomStringConvertible
59
63
60
64
var description : String {
@@ -96,6 +100,20 @@ internal enum RuntimeError: Error, CustomStringConvertible, LocalizedError, Pret
96
100
return " Transport failed with error: \( underlyingError. localizedDescription) "
97
101
case . handlerFailed( let underlyingError) :
98
102
return " User handler failed with error: \( underlyingError. localizedDescription) "
103
+ case . unexpectedResponseStatus( let expectedStatus, let response) :
104
+ return " Unexpected response, expected status code: \( expectedStatus) , response: \( response) "
105
+ case . unexpectedResponseBody( let expectedContentType, let response) :
106
+ return " Unexpected response body, expected content type: \( expectedContentType) , response: \( response) "
99
107
}
100
108
}
101
109
}
110
+
111
+ @_spi ( Generated)
112
+ public func throwUnexpectedResponseStatus( expectedStatus: String , response: Any ) throws -> Never {
113
+ throw RuntimeError . unexpectedResponseStatus ( expectedStatus: expectedStatus, response: response)
114
+ }
115
+
116
+ @_spi ( Generated)
117
+ public func throwUnexpectedResponseBody( expectedContent: String , body: Any ) throws -> Never {
118
+ throw RuntimeError . unexpectedResponseBody ( expectedContent: expectedContent, body: body)
119
+ }
0 commit comments