Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Display service response error message on application as an alert.

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?

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Display service response error message on application as an alert.

Thanks for the quick response.

Check the image for more clarity.

Image

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Display service response error message on application as an alert.

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);
}

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Display service response error message on application as an alert.

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?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Display service response error message on application as an alert.

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.

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Display service response error message on application as an alert.

I can't add response parameters values only request parameters values. Is it possible you check my projects?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Display service response error message on application as an alert.

How did you try to add response parameters? Adding response parameters is exactly the same as adding request parameters.

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Display service response error message on application as an alert.

As per your instructions:

Created Response parameters "code" and "error"

Image

Mapped response parameter "error" to local storage variable "error"

Image

Created Custom JavaScript on REST Service Success

Image

But still its not working as expected please advise.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Display service response error message on application as an alert.

Map the error to a label on a page.

Return to “Issues”