mirror of
https://github.com/bitwarden/ios.git
synced 2025-12-11 13:54:06 -06:00
32 lines
1015 B
Swift
32 lines
1015 B
Swift
import Foundation
|
|
import Networking
|
|
|
|
public extension Result where Success == HTTPResponse, Error: Error {
|
|
/// Convenience method to get a successful HTTPResponse result with APITestData.
|
|
static func httpSuccess(testData: APITestData) -> Result<HTTPResponse, Error> {
|
|
let response = HTTPResponse.success(
|
|
body: testData.data,
|
|
)
|
|
return .success(response)
|
|
}
|
|
|
|
/// Convenience method to get a successful result with a failed HTTPResponse.
|
|
static func httpFailure(
|
|
statusCode: Int = 500,
|
|
headers: [String: String] = [:],
|
|
data: Data = Data(),
|
|
) -> Result<HTTPResponse, Error> {
|
|
let response = HTTPResponse.failure(
|
|
statusCode: statusCode,
|
|
headers: headers,
|
|
body: data,
|
|
)
|
|
return .success(response)
|
|
}
|
|
|
|
/// Convenience method to get a failed HTTPResponse result.
|
|
static func httpFailure(_ error: Error) -> Result<HTTPResponse, Error> {
|
|
.failure(error)
|
|
}
|
|
}
|