Here is the Java server code I am using:
private Response createError(int code, String error) {
logger.error(error);
return Response.status(code).entity("{ \"errorMsg\": \""+error+"\"}").build();
}
And this is the client code:
function successCallback(response) {
self.lastResults = response.data;
self.filesToUpload.length = 0;
deferred.resolve(response.data);
}, function errorCallback(response) {
console.log(response.data.errorMsg);
self.filesToUpload.length = 0;
deferred.reject(JSON.stringify(response.data.errorMsg));
});
How can I access the string from the server response in the client?
I attempted unsuccessfully to use:
response.getEntity()
VM828:1 Uncaught TypeError: response.getEntity is not a function
at eval (eval at errorCallback (upload-service.js:114), <anonymous>:1:10)
at errorCallback (upload-service.js:114)
at processQueue (angular.js:16648)
at angular.js:16692
at Scope.$eval (angular.js:17972)
at Scope.$digest (angular.js:17786)
at Scope.$apply (angular.js:18080)
at done (angular.js:12210)
at completeRequest (angular.js:12436)
at XMLHttpRequest.requestLoaded (angular.js:12364)
(anonymous) @ VM828:1
errorCallback @ upload-service.js:114
processQueue @ angular.js:16648
(anonymous) @ angular.js:16692
$eval @ angular.js:17972
$digest @ angular.js:17786
$apply @ angular.js:18080
done @ angular.js:12210
completeRequest @ angular.js:12436
requestLoaded @ angular.js:12364
response.entity
undefined
JSON.stringify(response)
"{"data":"<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n<title>Error 500 Request failed.</title>\n</head>\n<body><h2>HTTP ERROR 500</h2>\n<p>Problem accessing /api/VoicesUploader/uploadFiles. Reason:\n<pre> Request failed.</pre></p><hr><a href=\"http://eclipse.org/jetty\">Powered by Jetty:// 9.3.15.v20161220</a><hr/>\n\n</body>\n</html>\n","status":500,"config":{"method":"POST","transformResponse":[null],"jsonpCallbackParam":"callback","headers":{"Accept":"application/json, text/plain, */*"},"url":"/api/VoicesUploader/uploadFiles","data":{}},"statusText":"Request failed."}"