Fix incorrect error message implementation in WordPressAPIError - #662
Conversation
mokagio
left a comment
There was a problem hiding this comment.
Would it be worth adding tests for the other errorDescription mappings, or since they are logic free we can do without?
I don't have an answer for that, but the criteria I usually use is "how likely is this to change and how important is it for us that it changes intentionally"
| return Self.unknownErrorMessage | ||
| case let .endpointError(error): | ||
| return error.errorDescription | ||
| return error.errorDescription ?? Self.unknownErrorMessage |
There was a problem hiding this comment.
The implementation should always return a non-nil error message
Gotcha. So even though errorDescription at the LocalizedError level allows for a nil value, we agree not to do that.
Would it be worth documenting it?
There was a problem hiding this comment.
Maybe... there could be an internal _errorDescription or strongErrorDescription or some other better name, that is String and public var errorDescription: String? could delegate to that. The idea being to have the compiler help us remember not to return any Optional.none.
There was a problem hiding this comment.
Good point. I didn't make more changes to the implementation because I thought the returning nil case is covered by the added unit tests. But I'll add a bit documentation too.
Co-authored-by: Gio Lodi <gio.lodi@automattic.com>
Description
I made two mistakes in the existing implementation:
WordPressAPIErrorconforms toLocalizedError.endpointErrorcase, becauseerrorDescriptionisString?.Testing Details
I have added unit tests in this PR to verify the fixes.
CHANGELOG.mdif necessary.