Handle HTTP 206 responses from timelines endpoint
This commit is contained in:
parent
4931665b45
commit
160f48679b
|
@ -83,7 +83,7 @@ public class Client {
|
||||||
completion(.failure(Error(request: request, type: .invalidResponse)))
|
completion(.failure(Error(request: request, type: .invalidResponse)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard response.statusCode == 200 else {
|
guard response.statusCode == 200 || request.additionalAcceptableHTTPCodes.contains(response.statusCode) else {
|
||||||
let mastodonError = try? Client.decoder.decode(MastodonError.self, from: data)
|
let mastodonError = try? Client.decoder.decode(MastodonError.self, from: data)
|
||||||
let type: ErrorType = mastodonError.flatMap { .mastodonError(response.statusCode, $0.description) } ?? .unexpectedStatus(response.statusCode)
|
let type: ErrorType = mastodonError.flatMap { .mastodonError(response.statusCode, $0.description) } ?? .unexpectedStatus(response.statusCode)
|
||||||
completion(.failure(Error(request: request, type: type)))
|
completion(.failure(Error(request: request, type: type)))
|
||||||
|
|
|
@ -38,6 +38,8 @@ extension Timeline {
|
||||||
request.queryParameters.append("local" => true)
|
request.queryParameters.append("local" => true)
|
||||||
}
|
}
|
||||||
request.range = range
|
request.range = range
|
||||||
|
// 206 can happen when the timeline is being regenerated and therefore is incomplete
|
||||||
|
request.additionalAcceptableHTTPCodes = [206]
|
||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ public struct Request<ResultType: Decodable>: Sendable {
|
||||||
let endpoint: Endpoint
|
let endpoint: Endpoint
|
||||||
let body: Body
|
let body: Body
|
||||||
var queryParameters: [Parameter]
|
var queryParameters: [Parameter]
|
||||||
|
var additionalAcceptableHTTPCodes: [Int] = []
|
||||||
|
|
||||||
init(method: Method, path: Endpoint, body: Body = EmptyBody(), queryParameters: [Parameter] = []) {
|
init(method: Method, path: Endpoint, body: Body = EmptyBody(), queryParameters: [Parameter] = []) {
|
||||||
self.method = method
|
self.method = method
|
||||||
|
|
Loading…
Reference in New Issue