You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// - urlString: URL domain + path as a string: `"abc.com/some/path"`
58
+
/// - body: Data?: The body data to send with a request
59
+
/// - header: A dictionary of HTTP Request Headers - `["Content-Type": "text", "Some Key": "Some Value"]`
60
+
/// - validator: `(Int) -> Bool` - A function to validate the response code of the request. By default, makeRequest() will fail if the status code does not fall within the 200 - 299 range. To override this, pass in a function that compares the status code and returns a boolean. True == success, False == failure. Upon failure an error will be thrown that contains the HTTPURLResponse for inspection.
61
+
///
62
+
/// - Returns: AnyPubliser<Data, Error>
63
+
///
64
+
/// -- Headers
65
+
///
66
+
/// By default all requests have the `["Accept-Encoding": "gzip;q=1.0,compress;q=0.5"]` header included.
67
+
///
68
+
/// All `.post, .put, & .patch` requests also contain `["Content-Type": "application/json"]` by default.
69
+
///
70
+
/// These values can be overridden by including those headers as arguments when calling this function
71
+
///
72
+
/// -- Validation
73
+
///
74
+
/// By default the validation checks for a 200-299 status code and fails if the code is out of bounds
Copy file name to clipboardExpand all lines: Sources/HTTPEngine/Utilities.swift
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,15 @@ public extension URLRequest {
7
7
}
8
8
}
9
9
10
+
11
+
/// A publisher that immediately throws
12
+
/// - Parameters:
13
+
/// - type: The expected type of the publisher
14
+
/// - error: The error to throw
15
+
/// - Returns: AnyPublisher<Type, Error> That fails immediately
16
+
///
17
+
/// -- Use case
18
+
/// Sometimes a function returns a publisher, but we need to unwap a value or perform a try catch before a publisher can be created. In this instance we can return this publisher instead to allow the publisher chain to handle those errors.
0 commit comments