Skip to content

Commit

Permalink
trying to determine when a primary resource error should be plural or…
Browse files Browse the repository at this point in the history
… not.
  • Loading branch information
mattpolzin committed Aug 24, 2022
1 parent 9e8c288 commit aec39fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Sources/JSONAPI/Document/DocumentDecodingError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public enum DocumentDecodingError: Swift.Error, Equatable {
self = .primaryResourceMissing
case .valueNotFound(let type, let context) where Location(context) == .data && type == UnkeyedDecodingContainer.self:
self = .primaryResourcesMissing
case .typeMismatch(let type, let context) where Location(context) == .data && type == UnkeyedDecodingContainer.self && context.debugDescription.hasSuffix("but found null instead."):
case .typeMismatch(let type, let context) where Location(context) == .data && type is _ArrayType.Type && context.debugDescription.hasSuffix("but found null instead."):
self = .primaryResourcesMissing
case .typeMismatch(_, let context) where Location(context) == .data && context.debugDescription.hasSuffix("but found null instead."):
self = .primaryResourceMissing
Expand Down Expand Up @@ -75,3 +75,6 @@ extension DocumentDecodingError: CustomStringConvertible {
}
}
}

private protocol _ArrayType {}
extension Array: _ArrayType {}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class DocumentDecodingErrorTests: XCTestCase {
) { error in
guard let docError = error as? DocumentDecodingError,
case .primaryResourcesMissing = docError else {
XCTFail("Expected primary resource missing error. Got \(error)")
XCTFail("Expected primary resources missing error. Got \(error)")
return
}

Expand Down

0 comments on commit aec39fc

Please sign in to comment.