简体   繁体   中英

How to handle HTTP 204 “no content” in Restangular POST?

I have a REST service to record user interface logs. The JavaScript is :

Restangular.all("log_tutor").post(information);

It works and I obtain an HTTP response "204 No content", which is expected for this service. But it writes in FireFox console "No element found".

How could it be possible to tell Restangular not to expect data from this call ? or to handle HTTP 204 code for this call only ?

The JAVA service is :

         @Provider
        @Path("log_tutor")
        public class TutorTraceRESTFacade {

        . . .

            @POST
            @Consumes({"application/xml", "application/json"})
            @Transactional
            @RolesAllowed("TUTOR")  
            public Response create(TutorTraceDetail _trace, @Context HttpServletRequest req) {
                _trace.setMessageReceivedTimestamp(new Date());
                HttpSession session = req.getSession();
                String sessionId = session.getId();
                LoginUser user = FormIDApplication.getInstance().getConnectedUser(sessionId);
                Long c = tutorTraceFacade.create(user.getLogin(), _trace);
                return Response.created(URI.create(c.toString())).build();
            }   
    . . .
}

Thank you.

考虑到您有一个Javascript对象logEntry ,其中包含要保存的数据,我会尝试:

Restangular.one('log_tutor').post(payload)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM