Ich möchte, dass mein Server einen indikativen Fehler an den eckigen js-Client sendet.angular js kann jax-rs nicht analysieren Antwort
sah ich diese Beispiele:
Example 7
Project: spice File: RequestService.java View source code 6 votes vote down vote up
@GET
@Path("date")
@Produces("text/plain")
public Response get(@Context Request request) {
final Date modificDate = getLastModificationDateFromDatastore();
final EntityTag entityTag = getEntityTagFromDatastore();
final ResponseBuilder resp = request.evaluatePreconditions(modificDate,
entityTag);
if (resp != null) {
return resp.build();
}
// Build new Response
final ResponseBuilder responseBuilder = Response.status(200);
responseBuilder.entity("This is the Entity from " + modificDate);
responseBuilder.lastModified(modificDate);
responseBuilder.tag(entityTag);
return responseBuilder.build();
}
und
Example 8
Project: zeppelin File: JsonResponse.java View source code 4 votes vote down vote up
public javax.ws.rs.core.Response build() {
ResponseBuilder r = javax.ws.rs.core.Response.status(status).entity(this.toString());
if (cookies != null) {
for (NewCookie nc : cookies) {
r.cookie(nc);
}
}
return r.build();
}
aber wenn mein Server-Code sendet:
catch (Exception ex)
{
String error = "RuntimeException: test11";
logger.error("update voice filed. Error: "+error);
return Response.serverError().entity(error).build();
}
im Client-Code kann ich nicht diese Fehlermeldung finden:
$http.put('api/foo', {voice : voice, isAddMode : isAddMode}).then(
function successCallback(response) {
..
}, function errorCallback(response) {
var responseStr = JSON.stringify(response)
console.log(responseStr);
deferred.reject(responseStr);
});
Ich bekomme Parsing-Fehler, aber im Allgemeinen kann ich nicht das richtige Mitglied in js finden.
SyntaxError: Unexpected token R in JSON at position 0
at JSON.parse (<anonymous>)
at fromJson (angular.js:1377)
at defaultHttpResponseTransform (angular.js:11003)
at angular.js:11094
at forEach (angular.js:357)
at transformData (angular.js:11093)
at transformResponse (angular.js:11914)
at processQueue (angular.js:16648)
at angular.js:16692
at Scope.$eval (angular.js:17972)
Angular versucht, 'RuntimeException: test11' zu analysieren, was kein gültiger JSON ist –