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

Show upload fail error dialog #420

Merged
merged 14 commits into from
Sep 25, 2024
Merged

Conversation

pinarol
Copy link
Contributor

@pinarol pinarol commented Sep 24, 2024

Closes #373

Description

Adds upload fail dialog.

Some errors are not suitable for retrying, so we don't show the retry option for them. These are the HTTP 400 errors for now. We know from REST API specs that these are validation errors about the image. Maybe we should make this assumption for all 4XX errors. I feel like it is better to show the Retry option in a false positive situation than not show it when it is actually needed.

Others look like this:

Testing Steps

SwiftUI demo app > Avatar Picker View

  • Try for both horizontal and vertical layouts
  • Try uploading an image when you are offline.
  • Observe: The error dialog appears with "Remove" and "Retry" options.

(It is a bit difficult to generate HTTP 400 errors, i had to comment out some image cropping code to get that not-square error ☝️. )

@pinarol pinarol changed the title Show upload fail action dialog Sep 24, 2024
var code: String { get }
/// Error message that comes from the REST API.
var message: String? { get }
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked the Gravatar backend, the errors have a standard format, a code and a message. The message is optional. So i think we can represent all the business errors with this protocol.

@pinarol pinarol marked this pull request as ready for review September 24, 2024 14:34
@pinarol pinarol requested review from andrewdmontgomery and etoledom and removed request for andrewdmontgomery September 24, 2024 14:34
@pinarol pinarol self-assigned this Sep 24, 2024
@pinarol pinarol added the enhancement New feature or request label Sep 24, 2024
@pinarol pinarol added this to the Milestone 4 - Quick Editor milestone Sep 24, 2024
@wpmobilebot
Copy link

wpmobilebot commented Sep 24, 2024

Gravatar SwiftUI Prototype Build📲 You can test the changes from this Pull Request in Gravatar SwiftUI Prototype Build by scanning the QR code below to install the corresponding build.
App NameGravatar SwiftUI Prototype Build Gravatar SwiftUI Prototype Build
Build Number1295
Version1.0
Bundle IDcom.automattic.gravatar-sdk-demo-swiftui.prototype-build
Commit6792f97
App Center BuildGravatar SDK Demo - SwiftUI #150
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.
@wpmobilebot
Copy link

wpmobilebot commented Sep 24, 2024

Gravatar UIKit Prototype Build📲 You can test the changes from this Pull Request in Gravatar UIKit Prototype Build by scanning the QR code below to install the corresponding build.
App NameGravatar UIKit Prototype Build Gravatar UIKit Prototype Build
Build Number1295
Version1.0
Bundle IDcom.automattic.gravatar-sdk-demo-uikit.prototype-build
Commit6792f97
App Center BuildGravatar SDK Demo - UIKit #151
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.
Copy link
Contributor

@etoledom etoledom left a comment

Choose a reason for hiding this comment

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

Looking good!

Added a small suggestion on code (up to you if it looks good).

And one other small detail to check before merging:

CleanShot 2024-09-25 at 09 18 25@2x

I'm not sure if the title should have a full stop here.

Comment on lines 68 to 74
do {
let error: ModelError = try data.decode()
return .invalidHTTPStatusCode(response: response, errorPayload: error)
} catch {
// if parsing the error fails then return invalidHTTPStatusCode without the payload.
return .invalidHTTPStatusCode(response: response)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are skipping handling the parsing error, maybe we can avoid using try-catch?

Suggested change
do {
let error: ModelError = try data.decode()
return .invalidHTTPStatusCode(response: response, errorPayload: error)
} catch {
// if parsing the error fails then return invalidHTTPStatusCode without the payload.
return .invalidHTTPStatusCode(response: response)
}
let error: ModelError? = try? data.decode()
return .invalidHTTPStatusCode(response: response, errorPayload: 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.

Nice. 👍

@pinarol
Copy link
Contributor Author

pinarol commented Sep 25, 2024

I'm not sure if the title should have a full stop here.

Hmm now that you pointed out I feel like it shouldn't. I'll remove the . 🤔

@pinarol pinarol merged commit 12cb93c into trunk Sep 25, 2024
9 checks passed
@pinarol pinarol deleted the wppinar/upload-fail-action-sheet branch September 25, 2024 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
3 participants