问题
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