custom error message for bad request in jhipster project

左心房为你撑大大i 提交于 2019-12-13 03:38:23

问题


I am trying to create a new Entity name if entity name is already exist i need to prompt the message.

Below is the code i have added to send error message. i am able to send the alert to dialog screen, but UI is printing as Object: object i am compare the json format success and failure i am sending the same but when success it is printing but when failure it printing has [object object]

@Timed
public ResponseEntity createEndpoint(@Valid @RequestBody Endpoint endpoint)         throws URISyntaxException {
log.debug("REST request to save Endpoint : {}", endpoint);
// endpoint.setId(1L);
if (endpoint.getId() != null) {
return ResponseEntity.badRequest().header("Failure", "A new endpoint cannot    already have an ID").body(null);
 }

Endpoint result =endpointRepository.findByName(endpoint.getName());
if (result!= null) {
    return ResponseEntity.badRequest().location(new URI("/api/endpoints/" + result.getId()))
    .headers(HeaderUtil.createEntityNameDuplicateAlert("Failure", result.getId().toString()))
    .body(result);

}else{
 result = endpointRepository.save(endpoint);
}
endpointSearchRepository.save(result);
return ResponseEntity.created(new URI("/api/endpoints/" + result.getId()))
        .headers(HeaderUtil.createEntityCreationAlert("endpoint", result.getId().toString()))
        .body(result);
}

But when i use the ResponseEntity.create method i am able to see the message in green color enitity .html .but i want display the error message in enitity dialogue box in in red color .

return ResponseEntity.created(new URI("/api/endpoints/" + result.getId()))
.headers(HeaderUtil.createEntityCreationAlert("endpoint", result.getId().toString()))
.body(result);

i tried both and for more information i am adding my error screen

来源:https://stackoverflow.com/questions/33202543/custom-error-message-for-bad-request-in-jhipster-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!