Skip to content

Consider adding isNetworkingError error type #75

Description

@sakuraehikaru

In one of our projects, we found ourselves often needing to identify networking errors, and so we've extended the error as such:

var isNetworkingError: Bool {
    switch errorCode {
    // NSURL Error Codes
    case NSURLErrorCancelled, NSURLErrorTimedOut, NSURLErrorCannotFindHost, NSURLErrorCannotConnectToHost, NSURLErrorNetworkConnectionLost, NSURLErrorNotConnectedToInternet, NSURLErrorSecureConnectionFailed:
        return true
    // POSIX Error Codes
    case Int(POSIXErrorCode.ECONNABORTED.rawValue), Int(POSIXErrorCode.ENETUNREACH.rawValue), Int(POSIXErrorCode.ECONNRESET.rawValue):
        return true
    default:
        return false
    }
}

This turned out to be quite useful, and maybe could be baked-in.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions