@@ -9,17 +9,17 @@ import Foundation
99
1010extension ReplicateAPI {
1111
12- /// Set of replicate api errors
12+ /// Set of replicate API errors
1313 @available ( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
14- public enum Errors : Error , Hashable {
15- 16- /// Base url error
14+ public enum Errors : Error , Hashable , LocalizedError {
15+
16+ /// Base URL error
1717 case baseURLError
1818
1919 /// Timeout retry policy
2020 case timeout
2121
22- /// Prediction was terminated Check out ``Prediction.Status``
22+ /// Prediction was terminated. Check out ``Prediction.Status``
2323 case terminated
2424
2525 /// Response error
@@ -30,5 +30,28 @@ extension ReplicateAPI{
3030
3131 /// Could not decode error format response
3232 case couldNotDecodeErrorContainer
33- }
33+ 34+ /// Provides a localized description for each error case.
35+ public var errorDescription : String ? {
36+ switch self {
37+ case . baseURLError:
38+ return NSLocalizedString ( " The base URL is invalid or missing. " , comment: " Base URL error " )
39+ 40+ case . timeout:
41+ return NSLocalizedString ( " The operation timed out. Please try again. " , comment: " Timeout error " )
42+ 43+ case . terminated:
44+ return NSLocalizedString ( " The prediction was terminated. Check its status for more details. " , comment: " Prediction terminated " )
45+ 46+ case . responseError( let responseError) :
47+ return responseError. localizedDescription
48+ 49+ case . invalidResponse( _, let message) :
50+ return message ?? NSLocalizedString ( " The response was invalid. " , comment: " Invalid response " )
51+ 52+ case . couldNotDecodeErrorContainer:
53+ return NSLocalizedString ( " Could not decode the error response. The format might be incorrect. " , comment: " Decoding error " )
54+ }
55+ }
56+ }
3457}
0 commit comments