Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/4.0 #112

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:5.9
//
// Package.swift
//
Expand Down Expand Up @@ -30,10 +30,12 @@ import PackageDescription
let package = Package(
name: "DBNetworkStack",
platforms: [
.iOS(.v9),
.tvOS(.v9),
.watchOS(.v2),
.macOS(.v10_10)
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6),
.macOS(.v10_15),
.visionOS(.v1),
.macCatalyst(.v14)
],
products: [
.library(
Expand All @@ -44,7 +46,11 @@ let package = Package(
.target(
name: "DBNetworkStack",
dependencies: [],
path: "Source"),
path: "Source",
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
name: "DBNetworkStackTests",
dependencies: ["DBNetworkStack"],
Expand Down
72 changes: 0 additions & 72 deletions Source/ContainerNetworkTask.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Source/HTTPMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Foundation

See [IETF document](https://tools.ietf.org/html/rfc7231#section-4.3)
*/
public enum HTTPMethod: String {
public enum HTTPMethod: String, Sendable {
case GET
case POST
case PUT
Expand Down
4 changes: 2 additions & 2 deletions Source/NetworkAccess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
import Foundation

/// `NetworkAccess` provides access to the network.
public protocol NetworkAccess {
public protocol NetworkAccess: Sendable {

/// Fetches a request asynchrony from remote location.
///
/// - Parameters:
/// - request: The request one wants to fetch.
/// - callback: Callback which gets called when the request finishes.
/// - Returns: the running network task
func load(request: URLRequest, callback: @escaping (Data?, HTTPURLResponse?, Error?) -> Void) -> NetworkTask
func load(request: URLRequest) async throws -> (Data, URLResponse)

}
34 changes: 19 additions & 15 deletions Source/NetworkError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import Foundation

/// `NetworkError` provides a collection of error types which can occur during execution.
public enum NetworkError: Error {
public enum NetworkError: Error, Sendable {
/// The error is unkonw
case unknownError
/// The request was cancelled before it finished
Expand All @@ -36,15 +36,11 @@ public enum NetworkError: Error {
/// Error on the server (HTTP Error 500...511)
case serverError(response: HTTPURLResponse?, data: Data?)
/// Parsing the body into expected type failed.
case serializationError(error: Error, data: Data?)
case serializationError(error: Error, response: HTTPURLResponse, data: Data?)
/// Complete request failed.
case requestError(error: Error)

public init?(response: HTTPURLResponse?, data: Data?) {
guard let response = response else {
return nil
}

public init?(response: HTTPURLResponse, data: Data) {
switch response.statusCode {
case 200..<300: return nil
case 401:
Expand Down Expand Up @@ -79,22 +75,30 @@ extension NetworkError: CustomDebugStringConvertible {
case .cancelled:
return "Request cancelled"
case .unauthorized(let response, let data):
return "Authorization error: \(response), response: ".appendingContentsOf(data: data)
return "Authorization error, response headers: \(response), response body: ".appendingContentsOf(data: data)
case .clientError(let response, let data):
if let response = response {
return "Client error: \((response)), response: ".appendingContentsOf(data: data)
return "Client error, response headers: \((response)), response body: ".appendingContentsOf(data: data)
}
return "Client error, response: ".appendingContentsOf(data: data)
case .serializationError(let description, let data):
return "Serialization error: \(description), response: ".appendingContentsOf(data: data)
return "Client error, response headers: nil, response body: ".appendingContentsOf(data: data)
case .serializationError(let error, let response, let data):
return "Serialization error: \(error), response headers: \(response), response body: ".appendingContentsOf(data: data)
case .requestError(let error):
return "Request error: \(error)"
case .serverError(let response, let data):
if let response = response {
return "Server error: \(String(describing: response)), response: ".appendingContentsOf(data: data)
if let response {
return "Server error, response headers: \(String(describing: response)), response body: ".appendingContentsOf(data: data)
} else {
return "Server error: nil, response: ".appendingContentsOf(data: data)
return "Server error: nil, response body: ".appendingContentsOf(data: data)
}
}
}
}

extension NetworkError: NetworkErrorConvertible {

public init(networkError: NetworkError) {
self = networkError
}

}
14 changes: 14 additions & 0 deletions Source/NetworkErrorConvertible.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// File.swift
//
//
// Created by Lukas Schmidt on 13.10.23.
//

import Foundation

public protocol NetworkErrorConvertible: Error {

init(networkError: NetworkError)

}
95 changes: 0 additions & 95 deletions Source/NetworkResponseProcessor.swift

This file was deleted.

77 changes: 0 additions & 77 deletions Source/NetworkService+Async.swift

This file was deleted.

Loading
Loading