diff --git a/Sources/OpenAPIRuntime/Errors/RuntimeError.swift b/Sources/OpenAPIRuntime/Errors/RuntimeError.swift index 4304b4cd..9c1fb0be 100644 --- a/Sources/OpenAPIRuntime/Errors/RuntimeError.swift +++ b/Sources/OpenAPIRuntime/Errors/RuntimeError.swift @@ -55,6 +55,10 @@ internal enum RuntimeError: Error, CustomStringConvertible, LocalizedError, Pret case transportFailed(any Error) case handlerFailed(any Error) + // Unexpected response (thrown by shorthand APIs) + case unexpectedResponseStatus(expectedStatus: String, response: any Sendable) + case unexpectedResponseBody(expectedContent: String, body: any Sendable) + // MARK: CustomStringConvertible var description: String { @@ -96,6 +100,20 @@ internal enum RuntimeError: Error, CustomStringConvertible, LocalizedError, Pret return "Transport failed with error: \(underlyingError.localizedDescription)" case .handlerFailed(let underlyingError): return "User handler failed with error: \(underlyingError.localizedDescription)" + case .unexpectedResponseStatus(let expectedStatus, let response): + return "Unexpected response, expected status code: \(expectedStatus), response: \(response)" + case .unexpectedResponseBody(let expectedContentType, let body): + return "Unexpected response body, expected content type: \(expectedContentType), body: \(body)" } } } + +@_spi(Generated) +public func throwUnexpectedResponseStatus(expectedStatus: String, response: any Sendable) throws -> Never { + throw RuntimeError.unexpectedResponseStatus(expectedStatus: expectedStatus, response: response) +} + +@_spi(Generated) +public func throwUnexpectedResponseBody(expectedContent: String, body: any Sendable) throws -> Never { + throw RuntimeError.unexpectedResponseBody(expectedContent: expectedContent, body: body) +}