-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rex
committed
Oct 25, 2024
1 parent
829ce80
commit 4b705ed
Showing
5 changed files
with
69 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Foundation | ||
|
||
/// An enumeration representing errors that can occur in the ToDo application. | ||
enum ToDoError: Error, LocalizedError, Equatable { | ||
case networkError(Error) | ||
case decodingError(Error) | ||
case invalidResponse(Int) | ||
case localError | ||
case unknownError | ||
|
||
var errorDescription: String? { | ||
switch self { | ||
case let .networkError(error): | ||
"Network error: \(error.localizedDescription)" | ||
case let .decodingError(error): | ||
"Decoding error: \(error.localizedDescription)" | ||
case let .invalidResponse(statusCode): | ||
"Invalid response from server: \(statusCode)" | ||
case .localError: | ||
"Unknown local error while fetching local storage data" | ||
case .unknownError: | ||
"Unknown error" | ||
} | ||
} | ||
|
||
static func == (lhs: ToDoError, rhs: ToDoError) -> Bool { | ||
switch (lhs, rhs) { | ||
case let (.networkError(error1), .networkError(error2)), | ||
let (.decodingError(error1), .decodingError(error2)): | ||
(error1 as NSError).code == (error2 as NSError).code && | ||
(error1.localizedDescription == error2.localizedDescription) | ||
case let (.invalidResponse(statusCode1), .invalidResponse(statusCode2)): | ||
statusCode1 == statusCode2 | ||
case (.localError, .localError): | ||
true | ||
case (.unknownError, .unknownError): | ||
true | ||
default: | ||
false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters