Alfresco exception message format - exception

I want to show only my message for alfresco workflow exception. But in alfresco exception message format is that
1. exception.class.name
2. ErrorLogNumber
3. Message
For example,
org.alfresco.service.cmr.workflow.WorkflowException: 05130007 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I only want to show 3.Message not 1.exception.class.name and 2.ErrorLogNumber. I can remove ErrorLogNumber from message by adding a custom exception class. But I can't remove 1.exception.class.name from error message.
Let me know how to implement that.

The solution is quite simple. Just throw AlfrescoRuntimeException with your message.
throw new AlfrescoRuntimeException("your.message");
In that case you get a message, but loose exception subtyping.
It is really hard to explain in words how I was suprised when saw exception handling in alfresco javaScript code:
onFormSubmitFailure: function FormManager_onFormSubmitFailure(response)
{
var failureMsg = null;
if (response.json && response.json.message && response.json.message.indexOf("Failed to persist field 'prop_cm_name'") !== -1)
{
failureMsg = this.msg("message.details.failure.name");
}
else if (response.json && response.json.message && response.json.message.indexOf("PropertyValueSizeIsMoreMaxLengthException") !== -1)
{
failureMsg = this.msg("message.details.failure.more.max.length");
}
else if (response.json && response.json.message && response.json.message.indexOf("org.alfresco.error.AlfrescoRuntimeException") == 0)
{
var split = response.json.message.split(/(?:org.alfresco.error.AlfrescoRuntimeException:\s*\d*\s*)/ig);
if (split && split[1])
{
failureMsg = split[1];
}
}
Alfresco.util.PopupManager.displayPrompt(
{
title: this.msg(this.options.failureMessageKey),
text: failureMsg ? failureMsg : (response.json && response.json.message ? response.json.message : this.msg("message.details.failure"))
});
},
As you can see they "catch" class name from java and replace it with message. I hope they provide more extensible way to handle custome exceptions.
P.S. Of course another way is to extend alfresco.js file and add one more if else condition for you exception.

Have you tried to override toString in your exception class? Or maybe to change logger implementation, if output is printed this way.

I had similar problem as you and failed to trace where this message is created even using debugger, quite tricky. Also anyone on Alfresco forums couldn't help me.
I developed a workaround instead of throwing an exception directly in java workflow task, I used a JS validation in form (the way I told you in another post), there I called a java webscript using ajax, which in case of error displayed JS alert box.

Related

Throwing newUserError in getData() function

I am currently building a data connector but would like to throw and error out to the user if the date range they have provided is not supported by my API endpoint (we don't have data for more than 90 days). I looked through the documentation and found this: https://developers.google.com/datastudio/connector/error-handling#user-facing-errors
And copied the code example exactly and tried to run it but my project still isn't showing the error dialog box back to the user.
I've also taken a look at how other people implement this in this repository (https://github.com/googledatastudio/community-connectors) but still can't see an issue with what I wrote.
function getData(request) {
try {
var dataSchema = getDataSchema(request);
var data = lookupRequestData(request, dataSchema);
} catch (e) {
console.log('pre throw');
// throw Error('some error!');
cc.newUserError()
.setDebugText('Error fetching data from API. Exception details: ' + e)
.setText('There was an error communicating with the service. Try again later, or file an issue if this error persists.')
.throwException();
console.log('post throw');
}
return {
schema: dataSchema,
rows: data
};
}
I can see both the pre throw and post throw strings in my log but there is still no error message being displayed. Just wondering if someone might be able to offer a bit of advice for other things to try.
Thanks

Ignore Undefined objects in array of arrays variable

In Google Apps Script, I'm pulling data from an API. In the code below, the "output" variable contains an array of arrays. There is always at least one ["Response"] object, but sometimes there are 2.
My problem is, the code below isn't returning the second object (["Response"][1]) when it is present. I tried removing the "if" statement, but I get an error saying "TypeError: Cannot read property "Product" from undefined".
Does anyone know how to get the second object when it's present and ignore it when it's not?
var data = reportAPI();
var applications = data["applications"];
var output = []
applications.forEach(function(elem,i) {
output.push(["ID",elem["Id"]]);
output.push([elem["Response"][0]["Product"],elem["Response"][0]["Status"]]);
if (["Response"][1] != null) {
output.push([elem["Response"][1]["Product"],elem["Response"][1]["Status"]]);
}
}
P.S. I would even be happy with replacing the undefined object with "", but I'm not sure how to do it.
How about this modification? Please think of this as one of several answers. I used forEach to elem["Response"]. By this, values can be pushed by the number of elem["Response"].
From :
applications.forEach(function(elem,i) {
output.push(["ID",elem["Id"]]);
output.push([elem["Response"][0]["Product"],elem["Response"][0]["Status"]]);
if (["Response"][1] != null) {
output.push([elem["Response"][1]["Product"],elem["Response"][1]["Status"]]);
}
}
To :
applications.forEach(function(elem) {
output.push(["ID",elem["Id"]]);
elem["Response"].forEach(function(elem2) {
output.push([elem2["Product"],elem2["Status"]]);
});
});
If this didn't work, please tell me. I would like to modify.
The example below helps to account for the cases where the Response[0] or Reponse[1] are not "undefined" or "null". Putting !() will turn the Boolean values for "undefined" or "null" to true.
applications.forEach(function(elem,i) {
output.push(["ID",elem.Id]);
if(!(elem.Reponse[0]))
output.push([elem.Response[0].Product,elem.Response[0].Status]);
if (!(elem.Response[1])) {
output.push([elem.Response[1].Product,elem.Response[1]Status]);
}
}

Couchbase gives badarg error

I Created simple couchbase spatial view to get list of report, but it gives {error: "error", reason: "badarg"} error.
Here is my view:-
function (doc, meta) {
if (doc.type == "report" && doc.location && doc.location.type && doc.location.coordinates) {
if(doc.location.type=='Point'){
emit(doc.location, {
summary:doc.summary
});
}
}
}
why this badarg error is coming, same view work on different doc.type
I used your View on an empty bucket and used the example query on the View UI page to test it:
_design/dev_test/_spatial/test?stale=false&connection_timeout=60000&limit=10&skip=0
On an empty bucket I got a successful but empty result, which was expected. As soon as I added the example document above, then I get your same error:
{error: "error", reason: "badarg"}
After some reducing of the View and of the document I found that with this particular document it fails because there are double quotes around the latitude and longitude coordinates in your location field (doc.location.coordinates). They need to be unquoted numbers if you want to pass your location field in as the geometry for the key. More on spatial views can be found here: http://docs.couchbase.com/admin/admin/Views/views-geospatial.html
Ideally, you would fix your issue by fixing the documents in your bucket. Whatever is creating your location field is putting the coordinates in as strings when they need to be floats. If that is not possible then you can try something similar to the following to doing the conversion in your View, at the very least this should prove that the string coordinates are the root cause of your problem:
function (doc, meta) {
if (doc.type == "report" && doc.location && doc.location.type && doc.location.coordinates) {
if(doc.location.type=='Point'){
for(var i=0; i<doc.location.coordinates.length; i++){
doc.location.coordinates[i] = parseFloat(doc.location.coordinates[i]);
}
emit(doc.location, {summary:doc.summary});
}
}
}

rtMedia api and json request

i have installed rtMedia on my web-site(which i have already installed buddypress) and now i’m trying to write an android application using the api of rtMedia but when i try to do a request like http://example.com/rtmedia_api/wp_login/?username=USER&password=PASS it display me “NOT FOUND”.
I have also tryed using the endpoint, like this http://example.com/wp-admin/admin-ajax.php/rtmedia_api/wp_login/?username=USER&password=PASS in this case it display me “0″.
I don’t understand how to use this api with json code to do json request.
I use also other plugin which have api and to perform a request i just need to type something like this http://example.com/api/?json=get_recent_posts/?cookie=COOKIE
Why it dosen’t work whith rtMedia api??
(sorry for my bad english :D )
This isn't the way rtMedia API will work.
Please check this doc about rtMedia JSON API.
For any queries regarding rtMedia, you can create a support request here
The rtmedia api plugin requires you to submit it via POST request (even though the confusing 'documentation' tells you otherwise with some functions). The easiest way to go about this is to create a form using the method="POST" and action="yourhost.domain/wordpress/wp-admin/admin-ajax.php". Another way to go about this is by using javascript (which I presume you will be using) and creating a formdata object like so: var formData_rtmedia = new FormData(); and appending (for example wp_login) the strings of your input field like this:
// _(id) is a function that returns document.getElementById(id)
var data1 = _('wp_login_input1').value;
var data2 = _('wp_login_input2').value;
if(data1 != undefined && data1 != '') {formData_rtmedia.append('username', data1);}
if(data1 != undefined && data1 != '') {formData_rtmedia.append('password', data2);}
Using the if dataX not equals undefined and not equals empty string check ensures the fields that are optional can be empty and won't populate the postdata object with empty or null values. The object can be sent using ajax (aka an XMLHttpRequest object) like this:
var xhr;
function ajax(method, url, async, formData) {
if(window.XMLHttpRequest) {xhr = new XMLHttpRequest();}
else {xhr = new ActiveXObject('Microsoft.XMLHTTP');}
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status != 200) {/* handle error */}
else {/* handle response */}
} else {
// display ajax loader or do something fancy
}
}
xhr.open(method, url, async);
xhr.send(formData);
}
and calling it in your rtmedia javascript file like so: ajax('POST', url, true, formData_rtmedia);

Why the param name is $accessToken?

Developers of the Drive SDK - or generally, the OAuth2.0 PHP client library!
In the apiClient.php there is a setAccessToken function:
public function setAccessToken($accessToken) {
if ($accessToken == null || 'null' == $accessToken) {
$accessToken = null;
}
self::$auth->setAccessToken($accessToken);
}
The #param of this function is something like this:
{"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
"expires_in":3600, "id_token":"TOKEN", "created":1320790426}
Why you name this parameter $accessToken if the access token is just a part of this JSON encoded string ??
It's very misleading i think.
When we go deeper and look at: $auth->setAccessToken($accessToken); in apiOAuth2.php
we see:
public function setAccessToken($accessToken) {
$accessToken = json_decode($accessToken, true);
if ($accessToken == null) {
throw new apiAuthException('Could not json decode the access token');
}
if (! isset($accessToken['access_token'])) {
throw new apiAuthException("Invalid token format");
}
$this->accessToken = $accessToken;
}
Look at the second if: $accessToken['access_token']. Whats the point of this? Access token inside an accessToken ?? :)
You should name the $accessToken parameter (the whole JSON string) of these functions to something else like $credentials or whatever because it's a little bit blurry... but tell me if I'm wrong.
As some of the comments mention I would post this either on the Google APIs PHP client library form: https://groups.google.com/forum/?fromgroups#!forum/google-api-php-client
Or file an issue on their issue tracker: http://code.google.com/p/google-api-php-client/issues/list
This will make sure that the engineers working on the PHP client library will be aware of this.
And you are right this makes perfect sense :)