Skip to content

Commit

Permalink
Improved error logs by adding title to APIErrorResponse and makin… (
Browse files Browse the repository at this point in the history
#63)

* Improved error logs by adding `title` to `APIErrorResponse` and making some values Optional.

* Bumped version to 2.0.3.
  • Loading branch information
michael-patzer authored Feb 16, 2021
1 parent 6bbf3b8 commit 08efbae
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.3] - 2021-02-16
### Fixed
- API error response parsing

## [2.0.2] - 2020-11-19
### Added
- Swift Package Support
Expand Down
2 changes: 1 addition & 1 deletion MailchimpSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'MailchimpSDK'
s.version = '2.0.2'
s.version = '2.0.3'
s.summary = 'Mailchimp SDK for iOS'

s.description = <<-DESC
Expand Down
8 changes: 4 additions & 4 deletions Sources/MailchimpSDK/MailchimpSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.0.2;
MARKETING_VERSION = 2.0.3;
PRODUCT_BUNDLE_IDENTIFIER = com.theRocketScienceGroup.MailchimpSDK;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -541,7 +541,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.0.2;
MARKETING_VERSION = 2.0.3;
PRODUCT_BUNDLE_IDENTIFIER = com.theRocketScienceGroup.MailchimpSDK;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand All @@ -561,7 +561,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.0.2;
MARKETING_VERSION = 2.0.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.theRocketScienceGroup.Mailchimp-SDKTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -580,7 +580,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.0.2;
MARKETING_VERSION = 2.0.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.theRocketScienceGroup.Mailchimp-SDKTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import Foundation

/// Basic struct to parse any possible API error responses
public struct APIErrorResponse: Codable {
public let title: String?
public let status: Int
public let type: String
public let detail: String
public let type: String?
public let detail: String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ struct AnzeeAPI: API {
} else if let jsonData = data, let errorResponse = try? JSONDecoder().decode(APIErrorResponse.self, from: jsonData) {
completionBlock(.failure(.apiError(response: errorResponse)))
} else if let httpResponse = response as? HTTPURLResponse, !(200..<300).contains(httpResponse.statusCode) {
completionBlock(.failure(.apiError(response: APIErrorResponse(status: 0, type: "Unexpected response", detail: ""))))
completionBlock(.failure(.apiError(response: APIErrorResponse(title: nil,
status: httpResponse.statusCode,
type: "Unexpected response",
detail: nil))))
} else if let jsonData = data {
completionBlock(.success(jsonData))
} else {
Expand Down

0 comments on commit 08efbae

Please sign in to comment.