title: How to handle and report to client Web Service Exceptions?
body: <p>I have two applications. A spring-boot web service and another that consumes it. I'm not sure how to handle exceptions and report them back to the client.</p>
  
  <p>The method that exposes the web-service:</p>
  
  <pre><code>//web service com springboot
      @PostMapping(value = "/save", produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE},
                      consumes = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})
      public Pessoa save(@RequestBody Pessoa pessoa) {    
          // email field is unique, might throw constraint violation...   
              return pessoaRepository.save(pessoa);               
      }
  
  </code></pre>
  
  <p>and the client application that consumes it (without spring, just javaEE Client API):</p>
  
  <pre><code>public Pessoa savePessoa(Pessoa pessoa) {
      Client client = ClientBuilder.newClient();
      WebTarget target = client.target(URL_WS+ "/save");
  
      Entity&lt;Pessoa&gt; data = Entity.entity(pessoa, MediaType.APPLICATION_XML_TYPE);
  
      pessoa = target.request(MediaType.APPLICATION_XML_TYPE).post(data, Pessoa.class);
  
      return pessoa;
  }
  </code></pre>
  
  <p>The email field of Pessoa is unique, and when saving can trigger some constraint violation exception.
  If there is an exception how can I properly report this to client?</p>