Skip to content
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

[MBL-1346] Support User Friendly Validate Checkout Error Messaging #2053

Merged
merged 11 commits into from May 13, 2024

Conversation

scottkicks
Copy link
Contributor

@scottkicks scottkicks commented May 6, 2024

📲 What

Displays more user-friendly error messaging from the backend if the ValidateCheckout call fails.

🤔 Why

Error messaging can now make more sense and provide more context to users than the generic "Something went wrong" messaging we currently have.

🛠 How

  • Add a new static func in ErrorEnvelope.swift that creates an envelope specific to this use case
  • Add a check in ValidateCheckoutEnvelope.envelopeProducer() that returns an ErrorEnvelope if we could parse the GraphAPI JSON, but the server deemed the checkout invalid.
  • Pass the returned error message, if there is one, to the error message banner

✅ Acceptance criteria

  • No changes to late pledge flow

Review Recommendation

  • All at once instead of commit by commit. Adjusted my plan along the way so the commits will likely be a bit confusing.

@scottkicks scottkicks self-assigned this May 6, 2024
we don't need to use the new errorTypes property right now
@scottkicks scottkicks force-pushed the scott/mbl-1346/late-pledge-error-messaging branch from 3abcd6d to 3fe9ff2 Compare May 6, 2024 20:12
@scottkicks scottkicks force-pushed the scott/mbl-1346/late-pledge-error-messaging branch from c9c767e to e4e5a25 Compare May 6, 2024 20:23
@scottkicks scottkicks force-pushed the scott/mbl-1346/late-pledge-error-messaging branch from 465e371 to fcfd273 Compare May 6, 2024 20:26
@scottkicks scottkicks requested a review from ifosli May 7, 2024 04:11
@scottkicks scottkicks marked this pull request as ready for review May 7, 2024 15:18
Copy link
Contributor

@ifosli ifosli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this approach confusing, since we'd now have a ValidateCheckoutEnvelope with valid = false and an ErrorEnvelope that basically mean the same thing. Left a more detailed comment with suggestions (that basically proposes we get rid of one of them). I'm glad we're getting better error messaging, though!

Also, note: Iirc, in the case where the error is "This payment method isn't valid for this project", I'm pretty sure we don't want to bump the user back to the confirm details page. This might be a different ticket/pr, but just wanted to raise it so you're aware of it in case it matters for your approach, since we'll want to differentiate between "error that restarts checkout" and "error that tells the user to just try something else from here".

@@ -14,6 +14,11 @@ extension ValidateCheckoutEnvelope {
guard let envelope = ValidateCheckoutEnvelope.validateCheckoutEnvelope(from: data) else {
return SignalProducer(error: .couldNotParseJSON)
}

if envelope.valid == false {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make sense to me. If we're always going to say that valid == false means we create an error envelope instead, why would we have a valid field at all on the ValidateCheckoutEnvelope? What do you think of either a) using the current valid field in the postCampaignCheckoutVM to decide if we should show an error banner or not or b) getting rid of the valid field entirely and instead create the errorEnvelope immediately once we see the checkout isn't valid?

Copy link
Contributor Author

@scottkicks scottkicks May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ifosli 🤔 Yea we could remove valid from ValidateCheckoutEnvelope and instead of
if envelope.valid == false {...} we could just check the checkout object directly like this

guard data.checkout?.isValidForOnSessionCheckout.valid == true else {...}

Is that what you mean?

Copy link
Contributor Author

@scottkicks scottkicks May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think that it's useful to differentiate between .couldNotParseJSON and .validateCheckoutError ErrorEnvelopes, though.

I also considered removing messages in the same way because the extra validateCheckoutEnvelope() seems excessive and not super useful for this case.

Copy link
Contributor Author

@scottkicks scottkicks May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and[ removed valid from the envelope](remove redundant valid property from ValidateCheckoutEnvelope) so that we just have the one!

As for updating the UX so that users who attempt to pledge with an invalid payment method, I already have a separate ticket to address this 😄 . Bessie should be adding an errorTypes array to this mutation that I think we can expose and then use to do that.

@scottkicks scottkicks force-pushed the scott/mbl-1346/late-pledge-error-messaging branch from c70d444 to 16957e3 Compare May 9, 2024 18:05
@scottkicks scottkicks requested a review from ifosli May 9, 2024 19:46
Copy link
Contributor

@ifosli ifosli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple minor things - please do handle the "server doesn't have any error messages for us" case before merging - but overall looks good!

return ErrorEnvelope(
errorMessages: [message],
ksrCode: .ValidateCheckoutError,
httpCode: 200,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 200 seems like a weird choice for the http code for an error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in this case, technically, the request was sent successfully even though there was an error on the backend. A 400 (Bad Request) didn't make much sense to me either.

@@ -14,6 +13,11 @@ extension ValidateCheckoutEnvelope {
guard let envelope = ValidateCheckoutEnvelope.validateCheckoutEnvelope(from: data) else {
return SignalProducer(error: .couldNotParseJSON)
}

guard data.checkout?.isValidForOnSessionCheckout.valid == true else {
return SignalProducer(error: .validateCheckoutError(envelope.messages.first ?? ""))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think the message param here should be optional instead of passing in the empty string, so that we can show the "Something went wrong" default (instead of a banner with an empty string) if the server doesn't give us an error message for some weird reason. Or we could just pass in the entire list of messages instead; that might make more sense actually.

@scottkicks scottkicks merged commit 8e37fd7 into main May 13, 2024
5 checks passed
@scottkicks scottkicks deleted the scott/mbl-1346/late-pledge-error-messaging branch May 13, 2024 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants