-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap .org XML RPC error
enum
in an Error
-conforming struct
Jumping through this hoop was necessary to avoid the Swift compiler automatically generating an error domain for the `Error` and making it impossible to successfully redefine the domain at the `CustomNSError` conformance site.
- Loading branch information
Showing
7 changed files
with
83 additions
and
47 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Foundation | ||
|
||
/// Error constants for the WordPress XML-RPC API | ||
@objc public enum WordPressOrgXMLRPCApiErrorCode: Int, CaseIterable { | ||
/// An error HTTP status code was returned. | ||
case httpErrorStatusCode | ||
/// The serialization of the request failed. | ||
case requestSerializationFailed | ||
/// The serialization of the response failed. | ||
case responseSerializationFailed | ||
/// An unknown error occurred. | ||
case unknown | ||
} | ||
|
||
public struct WordPressOrgXMLRPCApiError: Error { | ||
let code: WordPressOrgXMLRPCApiErrorCode | ||
} | ||
|
||
extension WordPressOrgXMLRPCApiError: LocalizedError { | ||
public var errorDescription: String? { | ||
return NSLocalizedString( | ||
"There was a problem communicating with the site.", | ||
comment: "A general error message shown to the user when there was an API communication failure." | ||
) | ||
} | ||
|
||
public var failureReason: String? { | ||
switch code { | ||
case .httpErrorStatusCode: | ||
return NSLocalizedString("An HTTP error code was returned.", comment: "A failure reason for when an error HTTP status code was returned from the site.") | ||
case .requestSerializationFailed: | ||
return NSLocalizedString("The serialization of the request failed.", comment: "A failure reason for when the request couldn't be serialized.") | ||
case .responseSerializationFailed: | ||
return NSLocalizedString("The serialization of the response failed.", comment: "A failure reason for when the response couldn't be serialized.") | ||
case .unknown: | ||
return NSLocalizedString("An unknown error occurred.", comment: "A failure reason for when the error that occured wasn't able to be determined.") | ||
} | ||
} | ||
} |
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