Handle 401 errors on instance timelines
This commit is contained in:
parent
825424cfba
commit
c114749519
|
@ -84,47 +84,58 @@ class InstanceTimelineViewController: TimelineViewController {
|
|||
// MARK: Timeline
|
||||
|
||||
override func handleLoadAllError(_ error: Swift.Error) async {
|
||||
switch (error as? Client.Error)?.type {
|
||||
case .mastodonError(422, _), .unexpectedStatus(422):
|
||||
collectionView.isHidden = true
|
||||
view.backgroundColor = .systemBackground
|
||||
|
||||
let image = UIImageView(image: UIImage(systemName: "lock.fill"))
|
||||
image.tintColor = .secondaryLabel
|
||||
image.contentMode = .scaleAspectFit
|
||||
|
||||
let title = UILabel()
|
||||
title.textColor = .secondaryLabel
|
||||
title.font = .preferredFont(forTextStyle: .title1).withTraits(.traitBold)!
|
||||
title.adjustsFontForContentSizeCategory = true
|
||||
title.numberOfLines = 0
|
||||
title.textAlignment = .center
|
||||
title.text = "This instance requires an account to view."
|
||||
|
||||
let stack = UIStackView(arrangedSubviews: [
|
||||
image,
|
||||
title,
|
||||
])
|
||||
stack.axis = .vertical
|
||||
stack.alignment = .center
|
||||
stack.spacing = 8
|
||||
stack.isAccessibilityElement = true
|
||||
stack.accessibilityLabel = title.text!
|
||||
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
image.widthAnchor.constraint(equalToConstant: 64),
|
||||
image.heightAnchor.constraint(equalToConstant: 64),
|
||||
|
||||
stack.leadingAnchor.constraint(equalToSystemSpacingAfter: view.safeAreaLayoutGuide.leadingAnchor, multiplier: 1),
|
||||
view.safeAreaLayoutGuide.trailingAnchor.constraint(equalToSystemSpacingAfter: stack.trailingAnchor, multiplier: 1),
|
||||
stack.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor),
|
||||
])
|
||||
|
||||
guard let error = error as? Client.Error else {
|
||||
await super.handleLoadAllError(error)
|
||||
return
|
||||
}
|
||||
let code: Int
|
||||
switch error.type {
|
||||
case .mastodonError(let c, _), .unexpectedStatus(let c):
|
||||
code = c
|
||||
default:
|
||||
await super.handleLoadAllError(error)
|
||||
return
|
||||
}
|
||||
guard code == 422 || code == 401 else {
|
||||
await super.handleLoadAllError(error)
|
||||
return
|
||||
}
|
||||
|
||||
collectionView.isHidden = true
|
||||
view.backgroundColor = .systemBackground
|
||||
|
||||
let image = UIImageView(image: UIImage(systemName: "lock.fill"))
|
||||
image.tintColor = .secondaryLabel
|
||||
image.contentMode = .scaleAspectFit
|
||||
|
||||
let title = UILabel()
|
||||
title.textColor = .secondaryLabel
|
||||
title.font = .preferredFont(forTextStyle: .title1).withTraits(.traitBold)!
|
||||
title.adjustsFontForContentSizeCategory = true
|
||||
title.numberOfLines = 0
|
||||
title.textAlignment = .center
|
||||
title.text = "This instance requires an account to view."
|
||||
|
||||
let stack = UIStackView(arrangedSubviews: [
|
||||
image,
|
||||
title,
|
||||
])
|
||||
stack.axis = .vertical
|
||||
stack.alignment = .center
|
||||
stack.spacing = 8
|
||||
stack.isAccessibilityElement = true
|
||||
stack.accessibilityLabel = title.text!
|
||||
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
image.widthAnchor.constraint(equalToConstant: 64),
|
||||
image.heightAnchor.constraint(equalToConstant: 64),
|
||||
|
||||
stack.leadingAnchor.constraint(equalToSystemSpacingAfter: view.safeAreaLayoutGuide.leadingAnchor, multiplier: 1),
|
||||
view.safeAreaLayoutGuide.trailingAnchor.constraint(equalToSystemSpacingAfter: stack.trailingAnchor, multiplier: 1),
|
||||
stack.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor),
|
||||
])
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
|
|
Loading…
Reference in New Issue