How to print error message on Windows Runtime that is not just the JSON string?

0 votes

Hello,

I am working on an application using the App42 services on Windows Runtime (Windows 8.1 and Windows Phone 8.1) and I am trying to print error messages in a clean way, but as of right now when I call GetMessage() on the App42Exception object that is passed into the OnException callback it simply returns the message as a JSON string.

Basically is it possible to provide a GetDetails() and a GetMessage() method that only returns those specific parts of the entire exception message instead of returning it formatted as a JSON string?
 
For example when I have an authentication error this is the result of GetMessage():
 
"{\"app42Fault\":{\"httpErrorCode\":404,\"appErrorCode\":2002,\"message\":\"Not Found\",\"details\":\"UserName/Password did not match. Authentication Failed.\"}}"
 
I would like to have a GetMessage() function that just returns "Not Found" and a GetDetails() function that returns "UserName/Password did not match. Authentication Failed" is this possible?
asked Dec 17, 2014 in App42 Cloud API-BaaS by feraask (45 points)
edited Dec 17, 2014 by feraask

1 Answer

0 votes

Hello Ferask,

Kindly find the below code snippet to overcome on this issue & let us know if it helps:

 

string messageJSON = exception.GetMessage();

JObject exceptionObj = JObject.Parse(messageJSON);

string details = exceptionObj["app42Fault"]["details"];

 

Thanks,

Himanshu Sharma

answered Dec 17, 2014 by hs00105 (2,005 points)
That worked exactly how I wanted, thanks!
Hi Himanshu,
How to do this for unity android/iOS?
is there any way to get above detail in unity?
Kindly find the below code snippet & let me know if it helps:
string messageJSON = exception.GetMessage();

JObject exceptionObj = JObject.Parse(messageJSON);

string details = exceptionObj["details"];

Thanks,
Himanshu Sharma
Hi Himansu,
Thanks for your reply. Above lines you mentioned I kept it like below. There is no GetMessage() while i am pressing e. Also error mark showing on JObject. Do I have to import any module to use this?

public void OnException (Exception e)
{
    result = e.ToString ();
    Debug.Log ("Exception : " + e);
    string messageJSON = e.GetMessage ();
       
    JObject exceptionObj = JObject.Parse (messageJSON);
       
    string details = exceptionObj ["details"];
}

I am using:
using System;
using com.shephertz.app42.paas.sdk.csharp.user;
using com.shephertz.app42.paas.sdk.csharp;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

am I missing something?
Hello Somnath,

Change your code snippet with below one & let me know if it helps:
public void OnException (Exception e)
{
    result = e.ToString ();
    App42Exception exception = (App42Exception)e;
    Debug.Log ("Exception : " + exception );
    string messageJSON = exception.GetMessage ();
        
    JObject exceptionObj = JObject.Parse (messageJSON);
        
    string details = exceptionObj ["details"];
}

Thanks
Himanshu Sharma
Himanshu,
Showing code error in JObject. Its in red color. In unity console showing error
"The type or namespace name `JObject' could not be found. Are you missing a using directive or an assembly reference?"
Got it,
I added SimpleJSON.JObject.and it worked.

public void OnException (Exception e)
{
App42Exception exception = (App42Exception)e;
Debug.Log ("Exception : " + exception);
string messageJSON = exception.GetMessage ();
SimpleJSON.JObject exceptionObj = SimpleJSON.JObject.Parse (messageJSON);
string details = exceptionObj ["details"];
Debug.Log(details);
}

Thanks
Hello Somnath,

Good to hear that your query has been resolved. Let me know if you have more questions for us.
Thanks,
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...