Skip to content

Commit

Permalink
Make WordPressOrgXMLRPCApiErrorCode into a nested enum
Browse files Browse the repository at this point in the history
  • Loading branch information
mokagio committed Apr 17, 2024
1 parent ac15e9a commit e8ee86f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _None._

### Breaking Changes

- The Objective-C-visible `WordPressOrgXMLRPCError` `enum` has been renamed to `WordPressOrgXMLRPCErrorCode` [#790]
- The Objective-C-visible `WordPressOrgXMLRPCError` `enum` has been renamed to `WordPressOrgXMLRPCErrorCode`, `WordPressOrgXMLRPCError.Code` in Swift [#790]

### New Features

Expand Down
27 changes: 14 additions & 13 deletions Sources/CoreAPI/WordPressOrgXMLRPCApiError.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
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

/// Error constants for the WordPress XML-RPC API
@objc public enum Code: 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
}

let code: Code
}

extension WordPressOrgXMLRPCApiError: LocalizedError {
Expand Down
2 changes: 1 addition & 1 deletion Tests/CoreAPITests/WordPressOrgXMLRPCApiErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import XCTest
class WordPressOrgXMLRPCApiErrorTests: XCTestCase {

func testNSErrorBridging() throws {
for error in WordPressOrgXMLRPCApiErrorCode.allCases {
for error in WordPressOrgXMLRPCApiError.Code.allCases {
let xmlRPCError = try XCTUnwrap(WordPressOrgXMLRPCApiError(code: error))
let apiError = WordPressAPIError.endpointError(xmlRPCError)
let newNSError = apiError as NSError
Expand Down
2 changes: 1 addition & 1 deletion Tests/CoreAPITests/WordPressOrgXMLRPCApiTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class WordPressOrgXMLRPCApiTests: XCTestCase {
failure: { (error, _) in
expect.fulfill()
XCTAssertEqual(error.domain, WordPressOrgXMLRPCApiErrorDomain)
XCTAssertEqual(error.code, WordPressOrgXMLRPCApiErrorCode.httpErrorStatusCode.rawValue)
XCTAssertEqual(error.code, WordPressOrgXMLRPCApiError.Code.httpErrorStatusCode.rawValue)
XCTAssertEqual(error.localizedFailureReason, "An HTTP error code 404 was returned.")
XCTAssertNotNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyData as String])
XCTAssertNotNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])
Expand Down

0 comments on commit e8ee86f

Please sign in to comment.