Error 500 post angularjs jersey - javascript

This is the problem
Here is the code which call the jersey part :
$http.post('/easyshow/api/shows/add', selectedShows).then(
function(data) {
alert("Yes");
},
function(data, status, headers, config, statusText) {
alert("No");
console.log("data : " + data + "status : " + status + "headers : " + headers +
"config : " + config + "statusText : " + statusText);
});
And finally the jersey method :
#POST
#javax.ws.rs.Path("/add")
#Consumes(MediaType.APPLICATION_JSON)
public Response addShows(List<ScannedShow> body) {
...
Response res = Response.status(Response.Status.OK) // 200
.build();
return res;
}
There is no error serverside. Everythings works, the objects are created and stored. But there is always this error 500 so I never go to the success case of the then...

Related

Why I'am always getting "Duplicate Alert" error after doing update request?

I am writing Chrome Extension for Vtiger CRM.
I need to create ability to add value for "Proposal text" field in the CRM on project page.
Here is the docs: https://www.vtiger.com/docs/rest-api-for-vtiger#/Update
How I do it:
Get the project from Vtiger API.
Change value "cf_potentials_proposaltext" in the project object.
Make POST (as required by docs) request to update Vtiger API endpoint, send updated project object
Get "duplicate alert" response..
I am absolutely sure, since I checked that I am sending the modified project object - using the console.log 'Temprorary_1' (in vtigerAddProposal) and 'Temprorary_2'(in vtigerUpdatePotential), also checked changed value in Chrome dev console in Network tab..
Here is my code:
function vtigerAddProposal() {
var temprorary_potential;
var dialog = $('#dialog');
chrome.storage.sync.get(['proposal'], function(result) {
$.ajax( {
url: 'https://roonyx.od2.vtiger.com/restapi/v1/vtiger/default/retrieve',
type: 'GET',
data: {
'id': localStorage.getItem('vtiger_last_opportunity_id')
},
success: function( response ) {
temprorary_potential = response['result'];
console.log("Temprorary_1: " + JSON.stringify(temprorary_potential, null, 2));
temprorary_potential['cf_potentials_proposaltext'] = result.proposal;
vtigerUpdatePotential(temprorary_potential);
},
error: function (response) {
console.log("Failed to get opportunity from Vtiger.");
$('#dialog-inner-text').text("Vtiger: " + response.status + " " + response.statusText);
dialog.show(800);
console.log(response);
}
});
});
}
function vtigerUpdatePotential(data) {
var dialog = $('#dialog');
console.log("Temprorary_2: " + JSON.stringify(data, null, 2));
// Second Part
$.ajax( {
url: 'https://roonyx.od2.vtiger.com/restapi/v1/vtiger/default/update',
type: 'POST',
data: {
element: JSON.stringify(data)
},
success: function( response ) {
console.log("Successfully updated Vtiger potential.")
console.log(response);
localStorage.removeItem('vtiger_last_opportunity_id'); // в случае успеха удаляем oppId
},
error: function (response) {
console.log("Failed to update potential in Vtiger.")
$('#dialog-inner-text').text("Vtiger potential wasn't update: " + response.status + " " + response.statusText);
dialog.show(800);
console.log(response);
}
});
}
Thank you in advance.
Problem solved by using revise https://www.vtiger.com/docs/rest-api-for-vtiger#/Revise once instead of update. Thanks to #pinaki

How to send object to class parameter javascript?

I have a problem sending a parameter to the class. I want to do a class that supports error in AJAX. The working function looks like this:
function GetLastChangePass(UserId) {
var field =
{
id: UserId,
}
var fieldStringified = JSON.stringify(field)
$.ajax({
url: "/Users/LastChangePass",
method: 'PUT',
data: fieldStringified,
contentType: 'application/json; charset=utf-8',
success: (result) => {
if (result.includes('12.12.2000')) {
document.querySelector('#user-tslog').append('')
} else if (result == 'Not_tslog') {
document.querySelector('#user-tslog').append('')
}
else {
document.querySelector('#user-tslog').append(result)
}
},
error: (result) => {
addNewMessage("error", "Error")
console.error("fail responseText: " + result.responseText)
console.error("fail contentstatusText : " + result.statusText)
console.error("fail status TEST: " + result.status)
}
});
}
I made a class that looks like this:
class ErrorConsole {
constructor(result) {
this.result = result
}
error() {
console.error("fail responseText: " + this.result.responseText)
console.error("fail contentstatusText : " + this.result.statusText)
console.error("fail status : " + this.result.status)
}
}
Why is the parameter undefined after converting the function to what is below?
error: (result) => {
console.log(result) //===> there is object
addNewMessage("error", "Error");
err.error(result) //===> there is indefined
console.error("fail responseText: " + result.responseText)
console.error("fail contentstatusText : " + result.statusText)
console.error("fail status TEST: " + result.status)
}
You should create the ErrorConsole and passing result in the constructor and not in the function, so that way you can print object attributes:
error: (result) => {
console.log(result) //===> there is object
const err = new ErrorConsole(result)
addNewMessage("error", "Error");
err.error()
console.error("fail responseText: " + result.responseText)
console.error("fail contentstatusText : " + result.statusText)
console.error("fail status TEST: " + result.status)
}

how to show custom REST API error messages in javascript client

I have Java REST API generated using swagger, in that if client is unauthorized then then i am sending custom error messages in response
public Response collaborationCollabIdDelete(Integer collabId, SecurityContext securityContext, String authBase64String) throws NotFoundException {
// do some magic!
ErrorRequestObject erb;
ArrayList <ErrorRequestObject> erbs = new ArrayList<ErrorRequestObject>();
if (authBase64String == null)
{
erb = new ErrorRequestObject(); erb.setError("Missing Authorization in Header"); erb.setPath("Header:Authorization");
erb.setProposedSolution("Authorization Header should contain user:pwd:nhPath as Base64 string");
erbs.add(erb);
}
if (erbs.size() == 0)
{
//success code here
}
else
{
return Response.status(400).entity(erbs).build();
}
}
I call this API using ajax as follows,
$.ajax({
url : URL,
type : "DELETE",
dataType : "json",
contentType : "application/json",
async : false,
success : function(result){
Response.resolve(result);
console.log("Response : " + JSON.stringify(result));
}
});
now when i call this API with ajax call it without authorization in header it gives me 400 status that is fine as expected but how do i get error object created with java ? can anyone please tell me how do i get this error object at javascript client ?
Something like this:
$.ajax({
url : URL,
type : "DELETE",
dataType : "json",
contentType : "application/json",
async : false,
success : function(result){
Response.resolve(result);
console.log("Response : " + JSON.stringify(result));
},
error: function(err) { /* your code here*/})
});
You can use the error function like
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
Where,
The jqXHRobject, textStatus - a string describing the type of error that occurred and an optional exception object as errorThrown, if one occurred. So, you can manipulate the statusCode and everything from this parameters like,
jqXHR.status == 400

How to use $http post data to ssl enabled server in angularjs

$http.post(myurl, myreq).success(function(apiReply) {
if (! checkApiResponse(apiReply)){
console.log("failed to run action with error: " + apiReply.retcode + " " + apiReply.retbody)
return false
} else {
callback(apiReply)
}
}).error(function(data, status) {
var errmsg = "handle api request failed with status: "
errmsg += status + ", error response: " + data
console.log(errmsg)
ons.notification.alert({
//title: "错误",
//message: '连接服务器失败',
title: "提示",
message: "请检查您的网络环境",
buttonLabel: ['确认']
});
});
}
here is my way to post data ,when using http url,it works fine,but doesn't work when i use https url, what should i do?

Facebook story posting issue

I am setting up for posting story on facebook but I am getting following alert:
You, or this app's Open Graph Test User, must have published this action at least once.
I am getting id in the response but when I am clicking on that I am redirecting to "Page not found".
Here is my code :
FB.api(
'me/objects/appnamespace:objecttype',
'post',
{
object :{
app_id: myappId,
objectype: myurl,
title: "Sample Organization",
image: mylogo,
description: ""
}
},
function(response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
document.getElementById('result').innerHTML =
'Error: ' + response.error.message;
} else {
document.getElementById('result').innerHTML =
'<a href=\"https://www.facebook.com/me/activity/' +
response.id + '\">' +
'Story created. ID is ' +
response.id + '</a>';
}
}
);

Categories

Resources