User friendly error messages



  • In my app I allow register new user.
    If user will input email that already exist for registration, from Enginio I recieved next error:
    @"{"errors":[{"reason":"ValidationFailed","message":"has already been taken","property":"username"},{"reason":"ValidationFailed","message":"has already been taken","property":"email"}]}"@

    But I don't understand how to obtain from this message user friendly error string, such as "email already exist"?
    Of course, I can parse text and write logic that will create need message from enginio error string. But, I think that this is very bad way.

    Is exist way now for getting user friendly error messages?


  • Moderators

    I haven't use enginio personally but it seems that the ouput is in JSON format. You can parse it using "QJsonDocument":http://qt-project.org/doc/qt-5/qjsondocument.html and it's supporting classes if you are using C++ or you can straight away use javascript JSON too directly.



  • [quote author="p3c0" date="1408876313"]I haven't use enginio personally but it seems that the ouput is in JSON format. You can parse it using "QJsonDocument":http://qt-project.org/doc/qt-5/qjsondocument.html and it's supporting classes if you are using C++ or you can straight away use javascript JSON too directly.[/quote]

    Thank you, but I know this.
    The problem that I need to parse not only a json fields, I need to parse text in json fields value for understanding what occured on Enginio server and output user friendly error message.


  • Moderators

    @
    {"reason":"ValidationFailed","message":"has already been taken","property":"email"}]}"
    @

    According to the error message i think it means that the email has already taken i.e it already exist and hence it failed viz. is ValidationFailed



  • [quote author="p3c0" date="1408877064"]@
    {"reason":"ValidationFailed","message":"has already been taken","property":"email"}]}"
    @

    According to the error message i think it means that the email has already taken i.e it already exist and hence it failed viz. is ValidationFailed[/quote]

    Yes, I need to check reason field, watch for which property this error, and what happen in message. Then I need to concatinate these fields to "email already exist".
    But this is very hard way.
    For example, error message may be such as this:
    @{"reason":"ValidationFailed","message":"invalid format","property":"email"}]}@
    Now I must understand by message field that error not in email dupliicate, but in mistake on email string.
    Therefore, in code I must storage minimum two strings with different messages for creating user friendly error messages.
    But, if this strings changes or Enginio server can send this with little differences code will be not work.
    I mean that parsing error message by strings not a good idea.


  • Moderators

    bq. I mean that parsing error message by strings not a good idea.

    That is how the JSON works. Everything is in string format. Even Google Drive REST api's or One Drive api's return in JSON format.

    bq. But, if this strings changes or Enginio server can send this with little differences code will be not work.

    Most probably they wont change it, but if changed you may be notified beforehand.

    bq. Yes, I need to check reason field, watch for which property this error, and what happen in message. Then I need to concatinate these fields to “email already exist”.

    It won't be tough to extract these using JSON api's and in my opinion these Keys should not change.



  • I see two variants that is better then now:

    1. Enginio must send error code instead of error messages. In this case I can set user friendly errors by each error code.
    2. Enginio must send already user friendly messages.

    Situation that exist now I think is hard for outputing user friendly errors.
    Also, a big problem, that I didn't can find fully list of messages that can be in Enginio errorString.
    How to create user firendly messages in this case?


  • Moderators

    I too didn't find a list of error messages but according to me the error codes are user friendly already.
    Eg. username has already been taken or email has already been taken.
    Even they can be used directly as it properly conveys the message.



  • [quote author="p3c0" date="1408882169"]I too didn't find a list of error messages but according to me the error codes are user friendly already.
    Eg. username has already been taken or email has already been taken.
    Even they can be used directly as it properly conveys the message.[/quote]

    In this case I can concatinate successfully. But I think that in other cases this can not work.
    But also exist problem with localization. As I understand Enginio server send error string now only on English.


  • Moderators

    Right this may not work but probably other too will be user freindly messages. May be you should request these two features on bugreports.qt-project.org



  • Also exist problem that each errorString have different answer structure. For example, if user set invalid login he recieve next message:
    @"{"error":"invalid_grant","error_description":"invalid user credentials"}"@
    Here can see that field "message" is absent, but exist "error_decription".
    How to know for which messages error description where must be?


  • cid:52:privileges:purge

    [quote author="Milovidov" date="1408884851"]Also exist problem that each errorString have different answer structure. For example, if user set invalid login he recieve next message:
    @"{"error":"invalid_grant","error_description":"invalid user credentials"}"@
    Here can see that field "message" is absent, but exist "error_decription".
    How to know for which messages error description where must be?[/quote]

    Only OAuth2 errors have this different syntax (Enginio tries to return oauth errors as they are defined in RFC6749). It should be quite trivial to differentiate these authentication errors from validation errors.



  • Ok, let that I will concatinate "property" and "message" fields.
    But, what about translations? How I can tranlsate this message to other languages if Enginio sending on english language?


  • cid:52:privileges:purge

    I'm not really a Qt/C++ coder but maybe you could just pass "message" contents to "tr":http://qt-project.org/doc/qt-5/qobject.html#tr function? And "property" field can be used to match that message to UI element.



  • I can to do this only if I will know all strings that can be from enginio, but this information not exist.
    tr function can be used only for string literals.


  • cid:52:privileges:purge

    You can override those default validation messages when you define validators in Enginio Dashboard.



  • I don't can to change validators for "users" collection.
    !http://i.imgur.com/yXYpr3J.png?1(Validators)!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.