michalkalinowski- / kiturarequest Goto Github PK
View Code? Open in Web Editor NEWClient request module for Kitura framework
License: Apache License 2.0
Client request module for Kitura framework
License: Apache License 2.0
Currently Request
class stores and handles only RequestError
error types, but there are other error types including HTTPParserErrorType
that can be thrown in process
method.
Maybe there is some sense in handling them all in some way?
First solution i've come to is make both initializer and response methods (including callbacks) throwable so any error type can be handled by do ... catch
and result looks like this:
do {
try Request(method: .GET, invalidURL)
.response { request, response, data in
...
}
...
} catch let error as RequestError {
XCTAssertEqual(error, RequestError.InvalidURL)
} catch {
XCTFail()
}
Other solution i've come to is to switch RequestError
with ErrorProtocol
. With this test looks like this:
let testRequest = Request(method: .GET, invalidURL)
.response { request, response, data, error in
...
}
switch testRequest.error {
case let error as RequestError:
XCTAssertEqual(error, RequestError.InvalidURL)
default:
XCTFail()
}
Building on Ubuntu 15.10 with DEVELOPMENT-SNAPSHOT-2016-05-03-a
produces following errors:
/home/michal/clones/KituraRequest/Sources/KituraRequest/ParameterEncoding.swift:43:45: error: incorrect argument label in call (have 'url:resolvingAgainstBaseURL:', expected 'URL:resolvingAgainstBaseURL:')
guard let components = NSURLComponents(url: request.url!, resolvingAgainstBaseURL: false) else {
^~~~
URL
/home/michal/clones/KituraRequest/Sources/KituraRequest/ParameterEncoding.swift:55:63: error: argument type '[String : AnyObject]' does not conform to expected type 'AnyObject'
let data = try NSJSONSerialization.data(withJSONObject: parameters, options: options)
^~~~~~~~~~
/home/michal/clones/KituraRequest/Sources/KituraRequest/Request.swift:61:21: error: value of type 'NSMutableURLRequest' has no member 'httpBody'
if let body = urlRequest.httpBody {
^~~~~~~~~~ ~~~~~~~~
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.