IMO following approach would be better,

try {

// some logic goes here, that might throw an exception.

// e.g.
callOSGiService("org.wso2.is.portal.user.client.api.RecoveryMgtService","isNotificationBasedPasswordRe",
[]);

return {success: true, message: {title: "Success", body: "Security question
changed successfully."}}; // everything went smoothly

} catch(e) {

// In here you can compose a meaningful error message to display in the UI.
Something like follwing.

var msg = {title: "Cannot change the security question", body: "You don't
have enough permissions to change the security question of 'admin' user."};
return {success: false, message: msg};

}


On Mon, Mar 20, 2017 at 5:48 PM, Manuranga Perera <[email protected]> wrote:

> UUF team,
> So what is the best practice we need to document ? Currently I see people
> just wrapping in Java and re-throwing some kind of UI error. I don't think
> wiring UI specific logic in Java is the best way to do this. And it's
> annoying to pass a "isSuccess" all over the code.
>
> Maybe we should ask them to do it in JS ( using Nashorn catch (e if e
> instanceof TypeError))
> OR
> implement UUF native way to do it.
>
> EG:
>
> my-page.js
>     function onGet() {
>         return callOSGiService("org.wso2.is.portal.user.client.api.
> RecoveryMgtService","isNotificationBasedPasswordRe", []);
>     }
>
> my-page.hbs
>     <div>
>       {{#try}}
>          {{if this}}
>              <button> Recover my password </button>
>          {{else}}
>              <div class="notification info"> Notification based password
> recovery is not enabled for you ({{userId}}), please contact admin for
> manual recovery </div>
>          {{/if}}
>       {{catch}}
>          <div class="panel panel-danger">
>             <div class="panel-heading">Error occurred </div>
>             <div class="panel-body">
>                {{#javaErr "UserNotFoundException" httpCode="404"}}
> ER10293: User '{{userId}}' not available. {{/javaErr}}
>                {{#javaErr "IdentityRecoveryException"}} ER10294: Error
> during recovery process. {{secure "admin.user-mgt"}} {{e.message}} {{/secure}}
> {{/javaErr}}
>                {{#unknownErr}} ER10299: Something went wrong.
> {{/unknownErr}}
>                Please contact admin with the error code and request id
> {{@requestId}} for more information.
>            </div>
>          </div>
>       {{/try}}
>     </div>
>
> What do you think?
>
> On Mon, Mar 20, 2017 at 5:38 AM, SajithAR Ariyarathna <[email protected]>
> wrote:
>
>>
>>
>> On Mon, Mar 20, 2017 at 9:42 AM, Pushpalanka Jayawardhana <[email protected]
>> > wrote:
>>
>>> Hi All,
>>>
>>> Shall we add a section on 'Error handling' to the UUF best practices
>>> documentation to capture information on this?
>>>
>>> +1
>>
>>> On Thu, Feb 2, 2017 at 8:43 AM, Dakshika Jayathilaka <[email protected]>
>>> wrote:
>>>
>>>> +1 for KasunGs suggestion.
>>>>
>>>> Even UIExceptions can be different.
>>>>
>>>> *Types of UI errors*
>>>>
>>>>    - User input errors
>>>>    - App errors
>>>>    - Incompatible state errors
>>>>
>>>> IMHO depending on the permission level, above error messages can be
>>>> optimized to give optimal user experience.
>>>>
>>>> Regards,
>>>>
>>>> *Dakshika Jayathilaka*
>>>> PMC Member & Committer of Apache Stratos
>>>> Associate Technical Lead
>>>> WSO2, Inc.
>>>> lean.enterprise.middleware
>>>> 0771100911 <077%20110%200911>
>>>>
>>>> On Wed, Feb 1, 2017 at 12:31 PM, KasunG Gajasinghe <[email protected]>
>>>> wrote:
>>>>
>>>>>
>>>>> To not disclose the back-end server details to the user, we should
>>>>> always catch the exceptions in the UUF app. If it is a UIException, then 
>>>>> we
>>>>> can show the error message to the user. Otherwise, we should show a 
>>>>> generic
>>>>> error message - something like "An error has occurred while processing 
>>>>> your
>>>>> request."
>>>>>
>>>>> If we know how to handle it, it is best if we handle it within the
>>>>> same page where the error has occurred. We already do this in multiple
>>>>> places. For example, see the code for user portal's login page when you
>>>>> enter invalid credentials.
>>>>>
>>>>> For unexpected errors, we can customize the error pages via the
>>>>> app.yaml's errorPages config.
>>>>>
>>>>> app.yaml:
>>>>> errorPages:
>>>>>   404: "/foundation/error/404"
>>>>>   401: "/login"
>>>>>   default: "/foundation/error/default"
>>>>>
>>>>> On Wed, Feb 1, 2017 at 12:20 PM, Ayesha Dissanayaka <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> What are the good practices around exception handling in UUF in
>>>>>> scenarios like handling exceptions thrown when callOSGiService.
>>>>>>
>>>>>> for example consider below method.
>>>>>>
>>>>>>>     /**
>>>>>>>      * Check whether the notification based password recovery enabled
>>>>>>>      */
>>>>>>>
>>>>>>>     function isNotificationBasedPasswordRecoveryEnabled() {
>>>>>>>         var checkMethod = "isNotificationBasedPasswordRe
>>>>>>> coveryEnabled";
>>>>>>>         return callOSGiService("org.wso2.is.p
>>>>>>> ortal.user.client.api.RecoveryMgtService",
>>>>>>>             checkMethod, []);
>>>>>>>
>>>>>>>     }
>>>>>>>
>>>>>>
>>>>>> If I don't catch exceptions within this method or whenever using 
>>>>>> *isNotificationBasedPasswordRecoveryEnabled
>>>>>> *method, in the UI I get below page.
>>>>>>
>>>>>>
>>>>>> ​What is the recommended way to handle this?
>>>>>>
>>>>>>    1. Handle exceptions around callOSGiService.
>>>>>>       - Then we'll have to repeat the same whenever we call osgi
>>>>>>       from a uuf app
>>>>>>       2. Handle at method invocation, and redirect to error page.
>>>>>>    3. Provide a generic message in the UI from UUF in such cases,
>>>>>>    unless handled in the app.
>>>>>>    4. Do we have to handle exceptions from osgi service itself?
>>>>>>    5. Other?
>>>>>>
>>>>>> ​Thanks!
>>>>>> -Ayesha
>>>>>>
>>>>>> --
>>>>>> *Ayesha Dissanayaka*
>>>>>> Software Engineer,
>>>>>> WSO2, Inc : http://wso2.com
>>>>>> <http://www.google.com/url?q=http%3A%2F%2Fwso2.com&sa=D&sntz=1&usg=AFQjCNEZvyc0uMD1HhBaEGCBxs6e9fBObg>
>>>>>> 20, Palmgrove Avenue, Colombo 3
>>>>>> E-Mail: [email protected] <[email protected]>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Dev mailing list
>>>>>> [email protected]
>>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> *Kasun Gajasinghe*Associate Technical Lead, WSO2 Inc.
>>>>> email: kasung AT spamfree wso2.com
>>>>> linked-in: http://lk.linkedin.com/in/gajasinghe
>>>>> blog: http://kasunbg.org
>>>>> phone: +1 650-745-4499 <(650)%20745-4499>, 77 678 0813
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Dev mailing list
>>>>> [email protected]
>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> Dev mailing list
>>>> [email protected]
>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>
>>>>
>>>
>>>
>>> --
>>> Pushpalanka.
>>> --
>>> Pushpalanka Jayawardhana, B.Sc.Eng.(Hons).
>>> Senior Software Engineer, WSO2 Lanka (pvt) Ltd;  wso2.com/
>>> Mobile: +94779716248
>>> Blog: pushpalankajaya.blogspot.com/ | LinkedIn: lk.linkedin.com/in/p
>>> ushpalanka/ | Twitter: @pushpalanka
>>>
>>>
>>
>>
>> --
>> Sajith Janaprasad Ariyarathna
>> Software Engineer; WSO2, Inc.;  http://wso2.com/
>> <https://wso2.com/signature>
>>
>
>
>
> --
> With regards,
> *Manu*ranga Perera.
>
> phone : 071 7 70 20 50
> mail : [email protected]
>



-- 
Sajith Janaprasad Ariyarathna
Software Engineer; WSO2, Inc.;  http://wso2.com/
<https://wso2.com/signature>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to