|
@@ -90,8 +90,7 @@ public class SWNetRequest: NSObject {
|
|
|
response(nil, PQError(msg: "非法地址", code: 0), nil)
|
|
response(nil, PQError(msg: "非法地址", code: 0), nil)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-// DebugPrint("网络请求-发起:url = \(url),parames = \(parames ?? [:])")
|
|
|
|
|
-
|
|
|
|
|
|
|
+ NTLog(message: "网络请求-发起:url = \(url),parames = \(parames ?? [:])")
|
|
|
sessionManager?.request(url, method: method, parameters: parames, encoding: encoding, headers: nil, requestModifier: { request in
|
|
sessionManager?.request(url, method: method, parameters: parames, encoding: encoding, headers: nil, requestModifier: { request in
|
|
|
request.timeoutInterval = bf_timeoutInterval
|
|
request.timeoutInterval = bf_timeoutInterval
|
|
|
}).responseJSON { jsonResponse in
|
|
}).responseJSON { jsonResponse in
|
|
@@ -99,15 +98,15 @@ public class SWNetRequest: NSObject {
|
|
|
case .success:
|
|
case .success:
|
|
|
if jsonResponse.data != nil {
|
|
if jsonResponse.data != nil {
|
|
|
let jsonData: Any = try! JSONSerialization.jsonObject(with: jsonResponse.data!, options: JSONSerialization.ReadingOptions.mutableContainers)
|
|
let jsonData: Any = try! JSONSerialization.jsonObject(with: jsonResponse.data!, options: JSONSerialization.ReadingOptions.mutableContainers)
|
|
|
- DebugPrint("网络请求-成功:url = \(jsonResponse.request?.url?.absoluteString ?? ""),jsonData = \(jsonData)")
|
|
|
|
|
|
|
+ NTLog(message: "网络请求-成功:url = \(jsonResponse.request?.url?.absoluteString ?? ""),jsonData = \(jsonData)")
|
|
|
response(jsonData, nil, jsonResponse.metrics?.taskInterval.duration)
|
|
response(jsonData, nil, jsonResponse.metrics?.taskInterval.duration)
|
|
|
- }else {
|
|
|
|
|
|
|
+ } else {
|
|
|
response(nil, PQError(msg: "数据为空", code: 1), jsonResponse.metrics?.taskInterval.duration)
|
|
response(nil, PQError(msg: "数据为空", code: 1), jsonResponse.metrics?.taskInterval.duration)
|
|
|
}
|
|
}
|
|
|
case let .failure(error):
|
|
case let .failure(error):
|
|
|
let errorResult = dealWithError(error: error)
|
|
let errorResult = dealWithError(error: error)
|
|
|
response(nil, PQError(msg: errorResult.msg, code: errorResult.code), jsonResponse.metrics?.taskInterval.duration)
|
|
response(nil, PQError(msg: errorResult.msg, code: errorResult.code), jsonResponse.metrics?.taskInterval.duration)
|
|
|
-// DebugPrint("网络请求-失败:url = \(jsonResponse.request?.url?.absoluteString ?? ""),error = \(String(describing: jsonResponse.error?.localizedDescription))")
|
|
|
|
|
|
|
+ NTLog(message: "网络请求-失败:url = \(jsonResponse.request?.url?.absoluteString ?? ""),error = \(String(describing: jsonResponse.error?.localizedDescription))")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -202,70 +201,73 @@ public class SWNetRequest: NSObject {
|
|
|
if let error = error as? AFError {
|
|
if let error = error as? AFError {
|
|
|
switch error {
|
|
switch error {
|
|
|
case let .invalidURL(url):
|
|
case let .invalidURL(url):
|
|
|
- DebugPrint("网球请求-处理错误:Invalid URL: \(url) - \(error.localizedDescription)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:Invalid URL: \(url) - \(error.localizedDescription)")
|
|
|
code = .valideUrl
|
|
code = .valideUrl
|
|
|
msg = "请求地址检验失败"
|
|
msg = "请求地址检验失败"
|
|
|
case let .parameterEncodingFailed(reason):
|
|
case let .parameterEncodingFailed(reason):
|
|
|
- DebugPrint("网球请求-处理错误:parameterEncodingFailed \(error.localizedDescription),Reason: \(reason)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:parameterEncodingFailed \(error.localizedDescription),Reason: \(reason)")
|
|
|
case let .multipartEncodingFailed(reason):
|
|
case let .multipartEncodingFailed(reason):
|
|
|
- DebugPrint("网球请求-处理错误:multipartEncodingFailed: \(error.localizedDescription),\(reason)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:multipartEncodingFailed: \(error.localizedDescription),\(reason)")
|
|
|
case let .responseValidationFailed(reason):
|
|
case let .responseValidationFailed(reason):
|
|
|
- DebugPrint("网球请求-处理错误:responseValidationFailed: \(error.localizedDescription),Reason: \(reason)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:responseValidationFailed: \(error.localizedDescription),Reason: \(reason)")
|
|
|
switch reason {
|
|
switch reason {
|
|
|
case .dataFileNil, .dataFileReadFailed:
|
|
case .dataFileNil, .dataFileReadFailed:
|
|
|
- DebugPrint("网球请求-处理错误:Downloaded file could not be read")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:Downloaded file could not be read")
|
|
|
case let .missingContentType(acceptableContentTypes):
|
|
case let .missingContentType(acceptableContentTypes):
|
|
|
- DebugPrint("网球请求-处理错误:Content Type Missing: \(acceptableContentTypes)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:Content Type Missing: \(acceptableContentTypes)")
|
|
|
case let .unacceptableContentType(acceptableContentTypes, responseContentType):
|
|
case let .unacceptableContentType(acceptableContentTypes, responseContentType):
|
|
|
- DebugPrint("网球请求-处理错误:Response content type: \(responseContentType) was unacceptable: \(acceptableContentTypes)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:Response content type: \(responseContentType) was unacceptable: \(acceptableContentTypes)")
|
|
|
case let .unacceptableStatusCode(code):
|
|
case let .unacceptableStatusCode(code):
|
|
|
- DebugPrint("网球请求-处理错误:Response status code was unacceptable: \(code)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:Response status code was unacceptable: \(code)")
|
|
|
case let .customValidationFailed(error: error):
|
|
case let .customValidationFailed(error: error):
|
|
|
- DebugPrint("网球请求-处理错误:customValidationFailed: \(error)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:customValidationFailed: \(error)")
|
|
|
}
|
|
}
|
|
|
case let .responseSerializationFailed(reason):
|
|
case let .responseSerializationFailed(reason):
|
|
|
- DebugPrint("网球请求-处理错误:Response serialization failed: \(error.localizedDescription)")
|
|
|
|
|
- DebugPrint("Failure Reason: \(reason)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:Response serialization failed: \(error.localizedDescription)")
|
|
|
|
|
+ NTLog(message: "Failure Reason: \(reason)")
|
|
|
case let .createUploadableFailed(error: error):
|
|
case let .createUploadableFailed(error: error):
|
|
|
- DebugPrint("网球请求-处理错误:createUploadableFailed: \(error.localizedDescription)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:createUploadableFailed: \(error.localizedDescription)")
|
|
|
case let .createURLRequestFailed(error: error):
|
|
case let .createURLRequestFailed(error: error):
|
|
|
- DebugPrint("createURLRequestFailed: \(error.localizedDescription)")
|
|
|
|
|
|
|
+ NTLog(message: "createURLRequestFailed: \(error.localizedDescription)")
|
|
|
case let .downloadedFileMoveFailed(error: error, source: source, destination: destination):
|
|
case let .downloadedFileMoveFailed(error: error, source: source, destination: destination):
|
|
|
- DebugPrint("网球请求-处理错误:downloadedFileMoveFailed: \(error.localizedDescription)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:downloadedFileMoveFailed: \(error.localizedDescription),\(source),\(destination)")
|
|
|
case .explicitlyCancelled:
|
|
case .explicitlyCancelled:
|
|
|
- DebugPrint("网球请求-处理错误:explicitlyCancelled: \(error.localizedDescription)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:explicitlyCancelled: \(error.localizedDescription)")
|
|
|
case let .parameterEncoderFailed(reason: reason):
|
|
case let .parameterEncoderFailed(reason: reason):
|
|
|
- DebugPrint("网球请求-处理错误:parameterEncoderFailed: \(error.localizedDescription)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:parameterEncoderFailed: \(error.localizedDescription),\(reason)")
|
|
|
case let .requestAdaptationFailed(error: error):
|
|
case let .requestAdaptationFailed(error: error):
|
|
|
- DebugPrint("网球请求-处理错误:requestAdaptationFailed: \(error.localizedDescription)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:requestAdaptationFailed: \(error.localizedDescription)")
|
|
|
case let .requestRetryFailed(retryError: retryError, originalError: originalError):
|
|
case let .requestRetryFailed(retryError: retryError, originalError: originalError):
|
|
|
- DebugPrint("网球请求-处理错误:requestRetryFailed: retryError = \(retryError),originalError = \(originalError)\(error.localizedDescription)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:requestRetryFailed: retryError = \(retryError),originalError = \(originalError)\(error.localizedDescription)")
|
|
|
case let .serverTrustEvaluationFailed(reason: reason):
|
|
case let .serverTrustEvaluationFailed(reason: reason):
|
|
|
- DebugPrint("网球请求-处理错误:serverTrustEvaluationFailed: - \(error.localizedDescription)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:serverTrustEvaluationFailed: - \(error.localizedDescription),\(reason)")
|
|
|
case .sessionDeinitialized:
|
|
case .sessionDeinitialized:
|
|
|
- DebugPrint("网球请求-处理错误:sessionDeinitialized: \(error.localizedDescription)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:sessionDeinitialized: \(error.localizedDescription)")
|
|
|
case let .sessionInvalidated(error: error):
|
|
case let .sessionInvalidated(error: error):
|
|
|
- DebugPrint("网球请求-处理错误:sessionInvalidated: \(error?.localizedDescription)")
|
|
|
|
|
- case let .sessionTaskFailed(error: error):
|
|
|
|
|
- DebugPrint("网球请求-处理错误:sessionTaskFailed:error = \(error) \(error.localizedDescription)")
|
|
|
|
|
- code = errorCode.init(rawValue: (error as? NSError)?.code ?? 1) ?? .nomal
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:sessionInvalidated: \(String(describing: error?.localizedDescription))")
|
|
|
|
|
+ case let .sessionTaskFailed(error: failError):
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:sessionTaskFailed:error = \(error) \(error.localizedDescription)")
|
|
|
|
|
+ code = errorCode.init(rawValue: (failError as? NSError)?.code ?? 1) ?? .nomal
|
|
|
if code == .netLost || code == .tomeOut {
|
|
if code == .netLost || code == .tomeOut {
|
|
|
msg = "网络不给力"
|
|
msg = "网络不给力"
|
|
|
}
|
|
}
|
|
|
case let .urlRequestValidationFailed(reason: reason):
|
|
case let .urlRequestValidationFailed(reason: reason):
|
|
|
- DebugPrint("网球请求-处理错误:urlRequestValidationFailed: \(error.localizedDescription)")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:urlRequestValidationFailed: \(error.localizedDescription),\(reason)")
|
|
|
}
|
|
}
|
|
|
- DebugPrint("网球请求-处理错误:Underlying error: \(String(describing: error.underlyingError))")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:Underlying error: \(String(describing: error.underlyingError))")
|
|
|
} else {
|
|
} else {
|
|
|
- DebugPrint("网球请求-处理错误:Unknown error: \(String(describing: error))")
|
|
|
|
|
|
|
+ NTLog(message: "网球请求-处理错误:Unknown error: \(String(describing: error))")
|
|
|
}
|
|
}
|
|
|
return (code.rawValue, msg)
|
|
return (code.rawValue, msg)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func DebugPrint(_ printString:String){
|
|
|
|
|
|
|
+/** 打印 */
|
|
|
|
|
+func NTLog<T>(message: T, fileName: String = #file, methodName: String = #function, lineNumber: Int = #line) {
|
|
|
#if DEBUG
|
|
#if DEBUG
|
|
|
-// print(printString)
|
|
|
|
|
|
|
+ print("👉func: \((fileName.components(separatedBy: "/").last)!).\(methodName)\n time: \(Int64(CFAbsoluteTimeGetCurrent() * 1000))\n line: \(lineNumber)\n message: \(message)👈")
|
|
|
|
|
+ #else
|
|
|
|
|
+
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|