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

Add ability to map AWSMobileClientError to underlying string message #1268

Closed
medvedNick opened this issue Mar 7, 2019 · 7 comments
Closed
Assignees
Labels
feature-request Request a new feature mobile client Issues related to AWSMobileClient pending-community-response Issue is pending response from the issue requestor

Comments

@medvedNick
Copy link
Contributor

I'd like to show user-friendly error messages received from AWSMobileClient. For instance,

AWSMobileClient.sharedInstance().signUp(username: loginInfo.phone, password: loginInfo.password) { signUpResult, error in
    // error is an AWSMobileClientError with associated message
....

I can add long switch-case for AWSMobileClientError enum or add the following check:

if let .usernameExists(message) = error {
    showAlertWithMessage(message)

but it would be great to have something like ErrorMappingHelper but for the opposite direction, which will convert AWSMobileClientError to string message and will be ready to be used out-of-the-box

@mutablealligator
Copy link
Contributor

Thank you @medvedNick for reporting to us. @rohandubal will be reviewing the PR #1270 and will provide updates soon.

@mutablealligator mutablealligator added the work in progress Issues was triaged and investigation done label Mar 9, 2019
@rohandubal
Copy link
Contributor

Hello @medvedNick

This is an interesting ask, to make sure we deliver it the correct way, I want to get your thoughts on couple things --

  1. AWSMobileClientError currently has error messages which are targeted to developer and sometimes the end user. How do you intend on making sure the end-use does not see the messages targeted for developer?
  2. Using the switch / else if of AWSMobileClientError, you can easily have a list of error types whose messages you can propagate. Wouldn't that be a better approach to make sure no messages that are intended for developer reaches the end user?

Best,
Rohan

@rohandubal rohandubal added the pending-community-response Issue is pending response from the issue requestor label Mar 12, 2019
@Czajnikowski
Copy link

As every case has it's associated message we can also take this approach:

public struct AWSMobileClientError: Error {
    public let type: AWSMobileClientErrorType
    public let message: String
}

public enum AWSMobileClientErrorType {
    case aliasExists
    case codeDeliveryFailure
    ...
}

Or just add a var message :

public enum AWSMobileClientError : Error {
    case aliasExists(message: String)
    case codeDeliveryFailure(message: String)
    ....
    var message: String {
        switch self {
            case let aliasExists(message: message):
                return message
            ....
        }
    }

This will still make selective reporting to the user possible.

@bernikovich
Copy link

bernikovich commented Jul 2, 2019

Wouldn't that be a better approach to make sure no messages that are intended for developer reach the end user?

So you're saying that we should never use these messages in UI. But what error should we display to a user when he can't log in.

@palpatim
Copy link
Member

We generally avoid propagating errors intended for the end user (although as @rohandubal noted there are some legacy exceptions). This should be something that falls squarely in the app domain. That way the app can handle localization of messages, aggregation of detailed error cases into simple user message, etc. @Czajnikowski's approach would be a good start, with the addition of localization using your app's localized resources.

That said...

While we would not recommend these as user-facing strings, but this would still be a useful addition even for debugging and internal reporting. I'll look at getting #1270 pulled in.

@palpatim palpatim removed the pending-community-response Issue is pending response from the issue requestor label Jul 17, 2019
@palpatim palpatim assigned palpatim and unassigned rohandubal Jul 17, 2019
@palpatim palpatim removed the work in progress Issues was triaged and investigation done label Jul 18, 2019
@palpatim
Copy link
Member

We released this in 2.10.0. Please let us know if you have any issues.

@stale
Copy link

stale bot commented Jul 25, 2019

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

@stale stale bot closed this as completed Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request a new feature mobile client Issues related to AWSMobileClient pending-community-response Issue is pending response from the issue requestor
Projects
None yet
Development

No branches or pull requests

6 participants