-1
サーバが角度jsクライアントに指示エラーを送信するようにします。angs jsがjax-rsの応答を解析できません
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();
}
と
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();
}
が、私のサーバー・コードが送信したとき:
catch (Exception ex)
{
String error = "RuntimeException: test11";
logger.error("update voice filed. Error: "+error);
return Response.serverError().entity(error).build();
}
をクライアントコードで、私はこのエラーメッセージを見つけることができません。
は、私はこれらの例を見て $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);
});
解析エラーが発生しますが、一般的にjsに正しいメンバーが見つかりません。
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が有効でない 'RuntimeException:test11'を解析しようとしています –