Map wrapped cancellation in the Amiibo live client to the cancelled error.

This commit is contained in:
javier committed 2026-10-25 19:29:23 +01:00
1 parent 44bfaca553
commit 51b1245ec3
4 files changed
+102 -2

No files matched your search

@@ -0,0 +1,48 @@
// ===----------------------------------------------------------------------===
//
// This source file is part of the Amiibo Service open source project
//
// Copyright (c) 2026 Röck+Cöde VoF. and the Amiibo Service project authors
// Licensed under Apache license v2.0
//
// See LICENSE for license information
// See CONTRIBUTORS for the list of Amiibo Service project authors
//
// SPDX-License-Identifier: Apache-2.0
//
// ===----------------------------------------------------------------------===
import Foundation
import HTTPTypes
import OpenAPIRuntime
/// A transport that throws a given error instead of sending the request, for testing purposes.
///
/// The error reaches the live client wrapped in a `ClientError`, as it would from a real transport.
struct ThrowingTransport: ClientTransport {
// MARK: Properties
/// The error to throw.
private let error: any Error
// MARK: Initializers
/// Initializes this transport.
/// - Parameter error: An error to throw.
init(error: any Error) {
self.error = error
}
// MARK: Functions
func send(
_ request: HTTPRequest,
body: HTTPBody?,
baseURL: URL,
operationID: String
) async throws -> (HTTPResponse, HTTPBody?) {
throw error
}
}