Hi Samitha,

Backend server should send a proper HTTP Error code instead of return a
value with error message. Here you can throw exception from Java and do the
log in jaggery level. In jaggery level you can detect exception type in
catch block by following approach in the code below.

if(e.javaException instanceof
org.wso2.carbon.apimgt.api.FaultGatewaysException){
 return {
error:true,
message:e.javaException.getFaultGateWayString()
};

 }

Regards,

On Wed, Mar 30, 2016 at 11:08 AM, Samitha Chathuranga <[email protected]>
wrote:

> Hi Sachith,
>
> So do you suppose to catch the error thrown from java, finally at the
> jaggery or even later at javascript?
> Anyway if we are printing the full stacktrace in Java side, what is the
> objective of throwing it to the jaggery ?
>
> Is it to indicate to the front end that an error was occurred in the back
> end? I guess this indication can also be done using a return value (boolean
> or something else) from java side function, but I'm afraid it is an
> accepted standard.
>
> Thanks,
> Samitha
>
> On Wed, Mar 30, 2016 at 10:45 AM, Sachith Withana <[email protected]>
> wrote:
>
>> Hi Samitha,
>>
>> From what I understand, you need to both print the full stack trace and
>> throw a proper message to the front end.
>>
>> If that so, you can catch the error, log it and throw a custom error from
>> the java side.
>>
>> Cheers,
>> Sachith
>>
>> On Wed, Mar 30, 2016 at 10:31 AM, Samitha Chathuranga <[email protected]>
>> wrote:
>>
>>> Hi,
>>>
>>> I am developing a feature in WSO2 PC and in it I have a JavaScript front
>>> end and a Java back end. To call java classes from the JavaScript I am
>>> using Jaggery in between the above two. So my question is what is the best
>>> practice in Exception handling and error logging in such a this scenario.
>>>
>>> As I understand I can come out with few options.
>>>
>>> Option 1- Catching the  exception in the Java class itself and log the
>>> complete error with an appropriate custom error message using 
>>> log.error(errMsg,
>>> e), without throwing exceptions from the method signature, using throws
>>> clause. (As we usually do in a sole java application). So here the
>>> exceptions are completely handled from the back end and doesn't come at
>>> least to the jaggery. And for the purpose of showing some error message to
>>> the front end user we can return a message or flag or something from the
>>> java function to the jaggery side. So at the jaggery side or even at the
>>> javascript, we can check that return value and show the error message as an
>>> alert and proceed depending conditionally on that return value.
>>>
>>> Option 2- We can throw the the exception in the catch block of java
>>> class using throw new ExceptionClassName("custom error message",e) and
>>> catch it in the jaggery file. But here I am getting the problem that we
>>> cannot log the complete long exception report using log.error(_ _) in
>>> jaggery. We can just print the custom error message set by us when throwing
>>> it from Java side. But I don't know is there any other way to trace that
>>> complete exception in jaggery. Anybody know something on it?
>>>
>>> Option 3- We can catch the error in the JavaScript, without catching in
>>> the Jaggery. But I don't think this is ok as we won't be able to print the
>>> exception in the server console if we do it so.
>>>
>>> I want to know what is the best practice in such a this scenario and if
>>> it is Option 2, what is the solution for the problem in it as mentioned
>>> there above. Appreciate support from somebody.
>>>
>>> Thanks,
>>> Samitha
>>>
>>> --
>>> Samitha Chathuranga
>>> Software Engineer, WSO2 Inc.
>>> lean.enterprise.middleware
>>> Mobile: +94715123761
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> [email protected]
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>> Sachith Withana
>> Software Engineer; WSO2 Inc.; http://wso2.com
>> E-mail: sachith AT wso2.com
>> M: +94715518127
>> Linked-In: <http://goog_416592669>
>> https://lk.linkedin.com/in/sachithwithana
>>
>
>
>
> --
> Samitha Chathuranga
> Software Engineer, WSO2 Inc.
> lean.enterprise.middleware
> Mobile: +94715123761
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 

*Tharik Kanaka*

WSO2, Inc |#20, Palm Grove, Colombo 03, Sri Lanka

Email: [email protected] | Web: www.wso2.com
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to