forked from zelo72/mastodon-ios
Merge pull request #340 from zacwest/fix-login into /develop
Handle onboarding authentication errors in /api/v1/instance
This commit is contained in:
commit
9a77ceac92
|
@ -37,7 +37,18 @@ extension Mastodon.API.Instance {
|
|||
)
|
||||
return session.dataTaskPublisher(for: request)
|
||||
.tryMap { data, response in
|
||||
let value = try Mastodon.API.decode(type: Mastodon.Entity.Instance.self, from: data, response: response)
|
||||
let value: Mastodon.Entity.Instance
|
||||
|
||||
do {
|
||||
value = try Mastodon.API.decode(type: Mastodon.Entity.Instance.self, from: data, response: response)
|
||||
} catch {
|
||||
if let response = response as? HTTPURLResponse, 400 ..< 500 ~= response.statusCode {
|
||||
// For example, AUTHORIZED_FETCH may result in authentication errors
|
||||
value = Mastodon.Entity.Instance(domain: domain)
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
return Mastodon.Response.Content(value: value, response: response)
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
|
|
|
@ -38,6 +38,25 @@ extension Mastodon.Entity {
|
|||
// https://github.com/mastodon/mastodon/pull/16485
|
||||
public let configuration: Configuration?
|
||||
|
||||
public init(domain: String) {
|
||||
self.uri = domain
|
||||
self.title = domain
|
||||
self.description = ""
|
||||
self.shortDescription = nil
|
||||
self.email = ""
|
||||
self.version = nil
|
||||
self.languages = nil
|
||||
self.registrations = nil
|
||||
self.approvalRequired = nil
|
||||
self.invitesEnabled = nil
|
||||
self.urls = nil
|
||||
self.statistics = nil
|
||||
self.thumbnail = nil
|
||||
self.contactAccount = nil
|
||||
self.rules = nil
|
||||
self.configuration = nil
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case uri
|
||||
case title
|
||||
|
|
Loading…
Reference in New Issue