feat(travel-album): 按当前景区创建相册及筛选订单
This commit is contained in:
@@ -67,10 +67,11 @@ final class APIClient {
|
||||
authTokenProvider = provider
|
||||
}
|
||||
|
||||
/// 发送强类型 APIRequest,并返回解包后的业务数据。
|
||||
/// 发送强类型 APIRequest;指定的业务错误码可以从非 2xx 响应中保留。
|
||||
func send<Response: Decodable>(
|
||||
_ apiRequest: APIRequest<Response>,
|
||||
tokenOverride: String? = nil
|
||||
tokenOverride: String? = nil,
|
||||
preservingBusinessErrorCodes: Set<Int> = []
|
||||
) async throws -> Response {
|
||||
let request = try DroneDockReadRequestPolicy.prepare(makeURLRequest(apiRequest, tokenOverride: tokenOverride))
|
||||
let isSimulation = session is any LocalSimulationURLSession
|
||||
@@ -118,7 +119,7 @@ final class APIClient {
|
||||
category: apiRequest.redactedLogCategory)
|
||||
}
|
||||
do {
|
||||
try validateHTTPResponse(response, data: data)
|
||||
try validateHTTPResponse(response, data: data, preservingBusinessErrorCodes: preservingBusinessErrorCodes)
|
||||
let value = try decodeEnvelope(Response.self, from: data)
|
||||
if let trace { droneDockLogSink(trace.message("response.decoded")) }
|
||||
return value
|
||||
@@ -310,14 +311,19 @@ final class APIClient {
|
||||
}
|
||||
|
||||
/// 校验 HTTP 层响应状态码,非 2xx 时提取错误信息。
|
||||
private func validateHTTPResponse(_ response: URLResponse, data: Data) throws {
|
||||
private func validateHTTPResponse(
|
||||
_ response: URLResponse,
|
||||
data: Data,
|
||||
preservingBusinessErrorCodes: Set<Int> = []
|
||||
) throws {
|
||||
guard let httpResponse = response as? HTTPURLResponse else {
|
||||
throw APIError.invalidResponse
|
||||
}
|
||||
|
||||
guard 200 ..< 300 ~= httpResponse.statusCode else {
|
||||
if let envelope = try? decoder.decode(ErrorEnvelope.self, from: data), envelope.code == 150015 {
|
||||
throw APIError.serverCode(150015, parseHTTPErrorMessage(data: data))
|
||||
if let code = (try? decoder.decode(ErrorEnvelope.self, from: data))?.code,
|
||||
code == 150015 || preservingBusinessErrorCodes.contains(code) {
|
||||
throw APIError.serverCode(code, parseHTTPErrorMessage(data: data))
|
||||
}
|
||||
throw APIError.httpStatus(httpResponse.statusCode, parseHTTPErrorMessage(data: data))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user