Skip to content

Commit

Permalink
resolved crash due to 408 in getShares api (#316)
Browse files Browse the repository at this point in the history
Co-authored-by: Shresth Pratap Singh <[email protected]>
  • Loading branch information
ShresthPratapSingh and Shresth Pratap Singh authored Jul 20, 2020
1 parent 8417420 commit 8d7eca2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class ServerApi {
func getShares(completion: @escaping (_ serverShares: [ServerShare]?) -> Void ) {
if serverRoute == nil{
completion(nil)
return
}

if serverAddress == nil{
Expand Down
1 change: 1 addition & 0 deletions AmahiAnywhere/AmahiAnywhere/Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ extension String {

extension Notification.Name {
static let HDATokenExpired = Notification.Name("HDATokenExpired")
static let HDAUnreachable = Notification.Name("HDAUnreachable")
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener {
presenter.getFiles(share, directory: directory)

NotificationCenter.default.addObserver(self, selector: #selector(expiredAuthTokenHDA), name: .HDATokenExpired, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(unreachableHDA), name: .HDAUnreachable, object: nil)
if #available(iOS 13.0, *) {
self.view.backgroundColor = UIColor.secondarySystemBackground
filesCollectionView.backgroundColor = UIColor.secondarySystemBackground
Expand Down Expand Up @@ -132,6 +133,15 @@ class FilesViewController: BaseUIViewController, GCKRemoteMediaClientListener {
}
}

@objc func unreachableHDA(){
let alertVC = UIAlertController(title: "Unable to reach HDA", message: "Please check if your HDA is connected and try again.", preferredStyle: .alert)
alertVC.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_) in
self.navigationController?.popToRootViewController(animated: true)
}))
self.present(alertVC, animated: true, completion: nil)
}


@objc func expiredAuthTokenHDA(){
let alertVC = UIAlertController(title: "Session Expired", message: "Your session expired or was lost. Please login again.", preferredStyle: .alert)
alertVC.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_) in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SharesViewController: BaseUIViewController, UICollectionViewDelegate, UICo

override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(unreachableHDA), name: .HDAUnreachable, object: nil)
if server?.name != "Welcome to Amahi"{
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Log out", style: .done, target: self, action: #selector(logOutTapped))

Expand Down Expand Up @@ -80,6 +81,14 @@ class SharesViewController: BaseUIViewController, UICollectionViewDelegate, UICo
self.present(alertVC, animated: true, completion: nil)
}

@objc func unreachableHDA(){
let alertVC = UIAlertController(title: "Unable to reach HDA", message: "Please check if your HDA is connected and try again.", preferredStyle: .alert)
alertVC.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_) in
self.navigationController?.popToRootViewController(animated: true)
}))
self.present(alertVC, animated: true, completion: nil)
}

@objc func logOutTapped(){
let serverName = ServerApi.shared!.getServer()?.name ?? ""
LocalStorage.shared.delete(key: serverName)
Expand Down
7 changes: 6 additions & 1 deletion AmahiAnywhere/AmahiAnywhere/Utils/Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ public class Network {
NotificationCenter.default.post(name: .HDATokenExpired, object: nil)
completion(nil)
}


if response.response?.statusCode == 408{
NotificationCenter.default.post(name:.HDAUnreachable, object: nil)
completion(nil)
}

// AmahiLogger.log("Request to \(url!) returned with STATUS CODE \(response.response?.statusCode)") // <<<<<<<<<<<<<
switch response.result {
case .success:
Expand Down

0 comments on commit 8d7eca2

Please sign in to comment.