OAuth2Response
open class OAuth2Response
Encapsulates a URLResponse to a URLRequest.
Instances of this class are returned from OAuth2Requestable
calls, they can be used like so:
perform(request: req) { response in
do {
let data = try response.responseData()
// do what you must with `data` as Data and `response.response` as HTTPURLResponse
}
catch let error {
// the request failed because of `error`
}
}
-
The data that was returned.
Declaration
Swift
open var data: Data?
-
The request that generated this response.
Declaration
Swift
open var request: URLRequest
-
The underlying HTTPURLResponse.
Declaration
Swift
open var response: HTTPURLResponse
-
Error reported by the underlying mechanisms.
Declaration
Swift
open var error: Error?
-
Designated initializer.
Declaration
Swift
public init(data: Data?, request: URLRequest, response: HTTPURLResponse, error: Error?)
Parameters
data
Data that was returned
request
The request to which we responded
response
The
HTTPURLResponse
to be represented by this instanceerror
Error that occurred when handling our request
-
Throws errors if something with the request went wrong, noop otherwise. You can use this to quickly figure out how to proceed in request callbacks.
If data is returned but the status code is >= 400, nothing will be raised except if there’s a 401 or 403.
Throws
Specific OAuth2Errors (.requestCancelled, .unauthorizedClient, .noDataInResponse) or any Error returned from the requestDeclaration
Swift
open func responseData() throws -> Data
Return Value
Response data
-
Uses
responseData()
, then decodes JSON usingFoundation.JSONSerialization
on the resulting data (if there was any).Throws
Any error thrown byresponseData()
, plus .jsonParserError if JSON did not decode into[String: Any]
Declaration
Swift
open func responseJSON() throws -> OAuth2JSON
Return Value
OAuth2JSON on success