Skip to content

Commit

Permalink
error change
Browse files Browse the repository at this point in the history
  • Loading branch information
Mephsito23 committed Jun 6, 2023
1 parent 036fed7 commit 50c742a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Sources/MyModel/MyError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

import Foundation

public enum MyError: Error {
public enum MyError: Error, Equatable {
public static func == (lhs: MyError, rhs: MyError) -> Bool {
lhs.id == rhs.id
}

var id: UUID { UUID() }
case errorDesc(String?)
case netEerrorData(Data, Int)
case fileError
Expand All @@ -16,11 +21,7 @@ public enum MyError: Error {
}

extension MyError: LocalizedError {
public var localizedDescription: String {
myLocalizedDescription
}

public var myLocalizedDescription: String {
public var errorDescription: String? {
switch self {
case let .errorDesc(desc):
return desc ?? ""
Expand Down
4 changes: 4 additions & 0 deletions Sources/MyNetWork/RequestManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public struct RequestManager<API> where API: APIProtocol {
httpResponse.statusCode == 200
else {
let httpResponse = response as? HTTPURLResponse
#if DEBUG
let errorStr = "httpResponseCode=>\(String(describing: httpResponse?.statusCode))\n" + (String(data: data, encoding: .utf8) ?? "network business error")
print(errorStr)
#endif
throw MyError.netEerrorData(data, httpResponse?.statusCode ?? -1)
}
return (data, response)
Expand Down

0 comments on commit 50c742a

Please sign in to comment.