swifter icon indicating copy to clipboard operation
swifter copied to clipboard

How to fail with an NSError?

Open be-meyer opened this issue 9 years ago • 1 comments

An URLSession data task can fail with an error according to:

open func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Swift.Void) -> URLSessionDataTask

Is there any way to fail with an NSError at the moment? I know that Nocilla for example is capable of failing like this.

If not i'd like to rise the proposal:

server["some/path"] = { _ in
    return HttpResponse.fail(NSError.notConnected)
}

This is an example where the OS is throwing a notConnected in case the customer does not have an internet connection. (Used in testing)

I'd like to see this in Swifter too.

be-meyer avatar Aug 16 '17 15:08 be-meyer

My fault got that Nocilla is doing something completely different.

be-meyer avatar Aug 16 '17 15:08 be-meyer