@@ -32,6 +32,9 @@ public class Satellite {
3232 /// The host domain such as `apple.com` or `icloud.com`.
3333 public let host : String
3434
35+ var _isGPSEnabled : Bool = false
36+ var _gpsLogs : [ String ] = [ ]
37+
3538 /// The base URL that is a combination of ``scheme`` and ``host``.
3639 /// `https://apple.com`
3740 public var baseURL : String {
@@ -70,14 +73,21 @@ public class Satellite {
7073 httpBody: httpBody
7174 )
7275 let ( data, response) = try await URLSession . shared. data ( for: urlRequest)
76+ showGPT ( String ( data: data, encoding: . utf8) ?? " Unknown data " )
7377 guard let httpResponse = response as? HTTPURLResponse else {
74- throw Satellite . Error. responseHasNoData
78+ let error = Satellite . Error. responseHasNoData
79+ showGPT ( error. description)
80+ throw error
7581 }
7682 guard ( 200 ..< 300 ) ~= httpResponse. statusCode else {
77- throw Satellite . Error. statusCode ( httpResponse. statusCode)
83+ let error = Satellite . Error. statusCode ( httpResponse. statusCode)
84+ showGPT ( error. description)
85+ throw error
7886 }
7987 guard let output = try ? JSONDecoder ( ) . decode ( ResponseType . self, from: data) else {
80- throw Satellite . Error. responseIsFailedDecoding
88+ let error = Satellite . Error. responseIsFailedDecoding
89+ showGPT ( error. description)
90+ throw error
8191 }
8292 return output
8393 }
@@ -106,12 +116,17 @@ public class Satellite {
106116 )
107117 let publisher = URLSession . shared
108118 . dataTaskPublisher ( for: urlRequest)
109- . tryMap { ( data, response) in
119+ . tryMap { [ weak self] ( data, response) in
120+ self ? . showGPT ( String ( data: data, encoding: . utf8) ?? " Unknown data " )
110121 guard let httpResponse = response as? HTTPURLResponse else {
111- throw Satellite . Error. requestIsFailed
122+ let error = Satellite . Error. requestIsFailed
123+ self ? . showGPT ( error. description)
124+ throw error
112125 }
113126 guard ( 200 ..< 300 ) ~= httpResponse. statusCode else {
114- throw Satellite . Error. statusCode ( httpResponse. statusCode)
127+ let error = Satellite . Error. statusCode ( httpResponse. statusCode)
128+ self ? . showGPT ( error. description)
129+ throw error
115130 }
116131 return data
117132 }
@@ -127,14 +142,19 @@ public class Satellite {
127142 httpHeaders: [ String : String ] ? ,
128143 httpBody: ( any Encodable ) ?
129144 ) throws -> URLRequest {
145+ showGPT ( " \( baseURL) / \( path) " )
130146 guard var components = URLComponents ( string: " \( baseURL) / \( path) " ) else {
131- throw Satellite . Error. urlIsInvalid
147+ let error = Satellite . Error. urlIsInvalid
148+ showGPT ( error. description)
149+ throw error
132150 }
133151 if let queryItems {
134152 components. queryItems = queryItems
135153 }
136154 guard let url = components. url else {
137- throw Satellite . Error. urlIsInvalid
155+ let error = Satellite . Error. urlIsInvalid
156+ showGPT ( error. description)
157+ throw error
138158 }
139159 var urlRequest = URLRequest ( url: url, timeoutInterval: 5.0 )
140160 urlRequest. httpMethod = httpMethod. rawValue
@@ -146,6 +166,7 @@ public class Satellite {
146166 if let httpBody {
147167 urlRequest. httpBody = try JSONEncoder ( ) . encode ( httpBody)
148168 }
169+ showGPT ( urlRequest. description)
149170 return urlRequest
150171 }
151172}
0 commit comments