Skip to content

Commit

Permalink
NetworkErrorConvertible + convinece init
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsprint09 committed Oct 13, 2023
1 parent 829f594 commit a0e2245
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Source/NetworkError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ extension NetworkError: CustomDebugStringConvertible {
}
}
}

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)

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

import Foundation

public extension ResourceWithError where E: NetworkErrorConvertible {

init(request: URLRequest, parse: @escaping (Data) throws -> Model) {
self.request = request
self.parse = parse
self.mapError = { E(networkError: $0) }
}

}

0 comments on commit a0e2245

Please sign in to comment.