From 8ecf05c6889228d6da08377ee4b15f4f95ff04cd Mon Sep 17 00:00:00 2001 From: pjechris Date: Thu, 8 May 2025 10:44:13 +0200 Subject: [PATCH] allow interceptor to throw --- Sources/SimpleHTTP/Interceptor/CompositeInterceptor.swift | 4 ++-- Sources/SimpleHTTP/Interceptor/Interceptor.swift | 2 +- Sources/SimpleHTTP/Session/Session.swift | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/SimpleHTTP/Interceptor/CompositeInterceptor.swift b/Sources/SimpleHTTP/Interceptor/CompositeInterceptor.swift index 15b8776..3880b74 100644 --- a/Sources/SimpleHTTP/Interceptor/CompositeInterceptor.swift +++ b/Sources/SimpleHTTP/Interceptor/CompositeInterceptor.swift @@ -14,10 +14,10 @@ public struct CompositeInterceptor: ExpressibleByArrayLiteral, Sequence { } extension CompositeInterceptor: Interceptor { - public func adaptRequest(_ request: Request) async -> Request { + public func adaptRequest(_ request: Request) async throws -> Request { var request = request for interceptor in interceptors { - request = await interceptor.adaptRequest(request) + request = try await interceptor.adaptRequest(request) } return request diff --git a/Sources/SimpleHTTP/Interceptor/Interceptor.swift b/Sources/SimpleHTTP/Interceptor/Interceptor.swift index c236e13..f64ea37 100644 --- a/Sources/SimpleHTTP/Interceptor/Interceptor.swift +++ b/Sources/SimpleHTTP/Interceptor/Interceptor.swift @@ -5,7 +5,7 @@ public typealias Interceptor = RequestInterceptor & ResponseInterceptor /// a protocol intercepting a session request public protocol RequestInterceptor { /// Should be called before making the request to provide modifications to `request` - func adaptRequest(_ request: Request) async -> Request + func adaptRequest(_ request: Request) async throws -> Request /// catch and retry a failed request /// - Returns: nil if the request should not be retried. Otherwise a publisher that will be executed before diff --git a/Sources/SimpleHTTP/Session/Session.swift b/Sources/SimpleHTTP/Session/Session.swift index ed64540..18a74d7 100644 --- a/Sources/SimpleHTTP/Session/Session.swift +++ b/Sources/SimpleHTTP/Session/Session.swift @@ -66,7 +66,7 @@ public class Session { extension Session { private func dataPublisher(for request: Request) async throws -> Response { - let modifiedRequest = await config.interceptor.adaptRequest(request) + let modifiedRequest = try await config.interceptor.adaptRequest(request) let urlRequest = try modifiedRequest .toURLRequest(encoder: config.encoder, relativeTo: baseURL, accepting: config.decoder)