Skip to content

Commit e6ea709

Browse files
calvincestarigh-action-runner
authored and
gh-action-runner
committed
refactor: More contextual multipart parsing errors (apollographql/apollo-ios-dev#628)
1 parent 4294a65 commit e6ea709

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Sources/Apollo/MultipartResponseParsingInterceptor.swift

+18-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ public struct MultipartResponseParsingInterceptor: ApolloInterceptor {
88

99
public enum ParsingError: Error, LocalizedError, Equatable {
1010
case noResponseToParse
11+
@available(*, deprecated, message: "Use the more specific `missingMultipartBoundary` and `invalidMultipartProtocol` errors instead.")
1112
case cannotParseResponse
1213
case cannotParseResponseData
14+
case missingMultipartBoundary
15+
case invalidMultipartProtocol
1316

1417
public var errorDescription: String? {
1518
switch self {
@@ -19,6 +22,10 @@ public struct MultipartResponseParsingInterceptor: ApolloInterceptor {
1922
return "The response data could not be parsed."
2023
case .cannotParseResponseData:
2124
return "The response data could not be parsed."
25+
case .missingMultipartBoundary:
26+
return "Missing multipart boundary in the response 'content-type' header."
27+
case .invalidMultipartProtocol:
28+
return "Missing, or unknown, multipart specification protocol in the response 'content-type' header."
2229
}
2330
}
2431
}
@@ -61,13 +68,22 @@ public struct MultipartResponseParsingInterceptor: ApolloInterceptor {
6168

6269
let multipartComponents = response.httpResponse.multipartHeaderComponents
6370

71+
guard let boundary = multipartComponents.boundary else {
72+
chain.handleErrorAsync(
73+
ParsingError.missingMultipartBoundary,
74+
request: request,
75+
response: response,
76+
completion: completion
77+
)
78+
return
79+
}
80+
6481
guard
65-
let boundary = multipartComponents.boundary,
6682
let `protocol` = multipartComponents.protocol,
6783
let parser = Self.responseParsers[`protocol`]
6884
else {
6985
chain.handleErrorAsync(
70-
ParsingError.cannotParseResponse,
86+
ParsingError.invalidMultipartProtocol,
7187
request: request,
7288
response: response,
7389
completion: completion

0 commit comments

Comments
 (0)