Skip to content

Commit

Permalink
Merge pull request #46 from 3sidedcube/feature/no-internet-notification
Browse files Browse the repository at this point in the history
Post `Notification` when a `.notConnectedToInternet` `URLError` is re…
  • Loading branch information
BenShutt authored Jul 2, 2020
2 parents 925fc20 + 6f44bd1 commit 8ae05e3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ThunderRequest/RequestController+Callbacks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ import os.log
public struct RequestNotificationKey {
public static let request = "TSCRequestNotificationRequestKey"
public static let response = "TSCRequestNotificationResponseKey"
public static let error = "TSCRequestNotificationErrorKey"
}

extension RequestController {

public static let ErrorDomain = "com.threesidedcube.ThunderRequest"

/// Name of `Notification` posted when the `Error` from a URL task is a `URLError`
public static let RequestDidURLErrorNotificationName =
Notification.Name(rawValue: "TSCRequestDidURLError")

public static let DidReceiveResponseNotificationName = Notification.Name(rawValue: "TSCRequestDidReceiveResponse")

public static let DidErrorNotificationName = Notification.Name("TSCRequestServerError")
Expand Down Expand Up @@ -74,6 +79,12 @@ extension RequestController {

NotificationCenter.default.post(name: RequestController.DidReceiveResponseNotificationName, object: nil, userInfo: requestInfo)

if let urlError = error as? URLError {
var userInfo = requestInfo
userInfo[RequestNotificationKey.error] = urlError
NotificationCenter.default.post(name: RequestController.RequestDidURLErrorNotificationName, object: nil, userInfo: userInfo)
}

if response?.status.isConsideredError == true {
NotificationCenter.default.post(name: RequestController.DidErrorNotificationName, object: nil, userInfo: requestInfo)
}
Expand Down

0 comments on commit 8ae05e3

Please sign in to comment.