Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Bump version to 2.21.4
Browse files Browse the repository at this point in the history
Generalize error code for NetworkManager Authenticators. Now considering error_code, error and developer_message for the error code.
  • Loading branch information
saeedbashir committed Mar 4, 2020
1 parent aa9acb0 commit 1a2e432
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
36 changes: 28 additions & 8 deletions Source/NSError+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ enum APIErrorCode : String {
}

fileprivate enum ErrorFields: String, RawStringExtractable {
case Code = "error_code"
case DeveloperMessage = "developer_message"
case error = "error"
case errorCode = "error_code"
case developerMessage = "developer_message"
}

extension NSError {
Expand All @@ -30,16 +31,35 @@ extension NSError {
}

func isAPIError(code: APIErrorCode) -> Bool {
guard let errorCode = errorInfo?[ErrorFields.Code.rawValue] as? String else { return false }
guard let errorCode = errorInfo?[ErrorFields.errorCode.rawValue] as? String else { return false }
return errorCode == code.rawValue
}

/// error_code can be in the different hierarchy. Like it can be direct or it can be contained in a dictionary under developer_message
private var errorInfo: Dictionary<AnyHashable, Any>? {
guard let errorInfo = userInfo[ErrorFields.DeveloperMessage.rawValue] as? Dictionary<AnyHashable, Any> else {
return userInfo
var errorVaule: Any?

if (userInfo[ErrorFields.errorCode.rawValue] != nil) {
errorVaule = userInfo[ErrorFields.errorCode.rawValue]
}
else if (userInfo[ErrorFields.error.rawValue] != nil) {
errorVaule = userInfo[ErrorFields.error.rawValue]
}
else if (userInfo[ErrorFields.developerMessage.rawValue] != nil) {
errorVaule = userInfo[ErrorFields.developerMessage.rawValue]
}

return errorInfo(value: errorVaule)
}

private func errorInfo(value: Any?) -> Dictionary<AnyHashable, Any>? {
var errorInfo: Dictionary<AnyHashable, Any>? = [:]
errorInfo?.setSafeObject(value, forKey: ErrorFields.errorCode.rawValue)

if errorInfo?.count ?? 0 > 0 {
return errorInfo
}
return errorInfo

return userInfo
}
}
6 changes: 3 additions & 3 deletions edX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5660,7 +5660,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CONFIGURATION_BUILD_DIR = "$PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
CURRENT_PROJECT_VERSION = 2.21.3;
CURRENT_PROJECT_VERSION = 2.21.4;
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -6118,7 +6118,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CONFIGURATION_BUILD_DIR = "$PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
CURRENT_PROJECT_VERSION = 2.21.3;
CURRENT_PROJECT_VERSION = 2.21.4;
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -6165,7 +6165,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CONFIGURATION_BUILD_DIR = "$PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
CURRENT_PROJECT_VERSION = 2.21.3;
CURRENT_PROJECT_VERSION = 2.21.4;
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down

0 comments on commit 1a2e432

Please sign in to comment.