-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Propagate parameter encoding error for URLRequest mapping #1248
Conversation
Codecov Report
@@ Coverage Diff @@
## 10.0.0-dev #1248 +/- ##
=============================================
Coverage ? 83.98%
=============================================
Files ? 24
Lines ? 768
Branches ? 0
=============================================
Hits ? 645
Misses ? 123
Partials ? 0
Continue to review full report at Codecov.
|
This is really cool, but I feel like this could be something we think about for version 10.0. We need to release 9.0 in a few. What do you think about it, @SD10? |
@sunshinejr I have no problem delaying this until v10.0 or even not going with this solution at all |
Damn, GitHub did let me remove the 9.0.0-dev branch while PRs were targeted to it still. Reopening! |
Hey @SD10, would you be up for finishing that one? Conflicts + Docs + Changelog is there to finish I believe? Other than that I think this looks good! |
@sunshinejr Yes, I will finish this up. I need about 2 days though |
Great! Take your time 👍 |
SwiftLint found issuesWarnings
Errors
Generated by 🚫 Danger |
That's what I get for trying to resolve a merge conflict in nano 😃 |
6a038a9
to
b12ae5b
Compare
@SD10 would you please rebase & fix the conflicts? I've merged few other PRs in the meantime. |
5c92b72
to
d1b4ca1
Compare
@sunshinejr Sure thing. Should be good to go if resolving the conflicts went well and CI is all green. Unless anyone else has any input/review. Giving it another look over myself now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @SD10! Seems good to me, but I think it would be awesome to get another pair of eyes on that one.
Yes, I'd really appreciate it if another @Moya/contributors gave their input. The goal of this PR is to expose more information about the failure of parameter encoding for a request. I don't want to hear a ton of complaints about having to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍 From an API perspective I think this makes a lot more sense, and migration is pretty easy. Good job!
let rhsRequest = try? rhs.urlRequest() | ||
if lhsRequest != nil, rhsRequest == nil { return false } | ||
if lhsRequest == nil, rhsRequest != nil { return false } | ||
if lhsRequest == nil, rhsRequest == nil { return lhs.hashValue == rhs.hashValue } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is totally fine, though I will point out that if two different Endpoints both fail to produce a urlRequest
, then they would be "equal". I'm sure that's fine, especially since it's consistent with hashValue
. The only consequences would be using an Endpoint
as key in a dictionary, or in a Set
. I think it's worth a comment, but otherwise this is totally 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If two different Endpoints both fail to produce a urlRequest
it will compare both endpoints using the hashValue of the url: String
property.
So if two different Endpoints both fail to produce a urlRequest
and they have the same String
for the url
-- they will be considered equal. I'll add a comment noting this behavior.
@@ -72,8 +72,8 @@ final class EndpointSpec: QuickSpec { | |||
|
|||
it("returns a nil urlRequest for an invalid URL") { | |||
let badEndpoint = Endpoint<Empty>(url: "some invalid URL", sampleResponseClosure: { .networkResponse(200, Data()) }, method: .get, task: .requestPlain, httpHeaderFields: nil) | |||
|
|||
expect(badEndpoint.urlRequest).to(beNil()) | |||
let urlRequest = try? badEndpoint.urlRequest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good – can we also add a test that makes sure the error thrown is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea 👍 Thanks for the input
As per @ashfurrow 's feedback I added tests to make sure I changed the implementation to throw the Truthfully, it was extremely hard to write a test that caught an error -- it even made me question the value of this change. This error will only ever be triggered when |
it("throws a .parameterEncoding error") { | ||
|
||
// Non-serializable type to cause serialization error | ||
class InvalidParameter {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
Awesome, great work! Let's leave it a few days in case anyone else has input. @Moya/core-team I wonder if we should target a new |
@ashfurrow This PR is already targeting branch |
Oops 🙈 |
4382d73
to
a684307
Compare
2a9fb06
to
42ecf86
Compare
I was rebasing 10.0.0-dev again as we had documentation changes, so I rebased this one as well. Sorry for trouble. |
Cool, looks good to merge on 🍏 |
Great! Thanks for all your hard work on that one, @SD10 😉 |
Changes:
Adds:
MoyaError.parameterEncoding(Swift.Error) case
Refactors:
urlRequest
->urlRequest()
(now throwing)Summary of Pull Request:
As discussed in #1247 I saw that it would be really easy to pass on the errors thrown when attempting to encode
URLRequest
parameters.All that had to be done is convert
Endpoint
'surlRequest
property to a throwing function and pass the error to the.failure
closure inMoyaProvider.defaultRequestMapping
.Personally, I'm not too fond of having to call
try
now when accessing anEndpoint
'surlRequest
. Therefore, I mostly consider this "research" unless any of you think there's value in it.