Page 1 of 5
Display service response error message on application as an alert.
Posted: Mon Oct 08, 2012 11:32 am
by Kevin
I would like to display the service response error messages on an application as an alert. How can I go about it?
I'm using parse.com and for example if a user enters a username that is already in use, the service response error message indicates that the username is already taken. How can I display such a message on the application as an alert?
Display service response error message on application as an alert.
Posted: Mon Oct 08, 2012 11:35 am
by Maryna Brodina
Display service response error message on application as an alert.
Posted: Mon Oct 08, 2012 11:55 am
by Kevin
Thanks for the quick response.
Check the image for more clarity.
Server response:
{
"code": 202,
"error": "username temeke already taken"
}
I want to be able to display the exact same message to the user on an alert.
I need help coming up with the Custom JavaScript code. Thanks.
Display service response error message on application as an alert.
Posted: Mon Oct 08, 2012 12:34 pm
by Maryna Brodina
The easiest way is to map Service to localStorage as shown here http://help.gotiggr.com/documentation.... The main idea is to save Error into localStorage and then get it with JS. Please try to run this JS on Service success event:
var errorText = localStorage.getItem('error') ;
if(errorText != ""){
localStorage.removeItem('error');
alert(errorText);
}
Display service response error message on application as an alert.
Posted: Mon Oct 08, 2012 1:34 pm
by Kevin
Thanks. I tried what you suggested but nothing happens. No alert at all. I even went ahead and moved the JS on Service Error or Complete, at least here i get an alert but with message null.
Can I share my project with you, so that you can check where I might be going wrong?
Display service response error message on application as an alert.
Posted: Mon Oct 08, 2012 1:42 pm
by Maryna Brodina
In addition to your standard response parameters, you could add this at the end: "code": 202, "error": "username temeke already taken" when an error occurs, only the two above fields will be matched and used. So, you could map 'error' to a label and the message will be displayed.
Display service response error message on application as an alert.
Posted: Mon Oct 08, 2012 2:37 pm
by Kevin
I can't add response parameters values only request parameters values. Is it possible you check my projects?
Display service response error message on application as an alert.
Posted: Mon Oct 08, 2012 2:48 pm
by Maryna Brodina
How did you try to add response parameters? Adding response parameters is exactly the same as adding request parameters.
Display service response error message on application as an alert.
Posted: Mon Oct 08, 2012 6:28 pm
by Kevin
As per your instructions:
Created Response parameters "code" and "error"
Mapped response parameter "error" to local storage variable "error"
Created Custom JavaScript on REST Service Success
But still its not working as expected please advise.
Display service response error message on application as an alert.
Posted: Mon Oct 08, 2012 7:02 pm
by maxkatz
Map the error to a label on a page.