title: JAX-RS service throwing a 404 HTTPException but client receiving a HTTP 500 code
body: <p>I have a RESTful resource, which calls a EJB to make a query. If there is no result from the query, the EJB throws a EntityNotFoundException. In the catch block, it will be thrown a javax.xml.ws.http.HTTPException with code 404.</p>
  
  <pre><code>@Stateless
  @Path("naturezas")
  public class NaturezasResource {
  
      @GET
      @Path("list/{code}")
      @Produces(MediaType.APPLICATION_JSON)
      public String listByLista(
              @PathParam("code") codeListaNaturezasEnum code) {
          try {
              List&lt;NaturezaORM&gt; naturezas = this.naturezaSB
                      .listByListaNaturezas(code);
              ObjectMapper mapper = new ObjectMapper();
              return mapper.writeValueAsString(naturezas);
          } catch (EntityNotFoundException e) { // No data found
              logger.error("there is no Natures with the code " + code);
              throw new HTTPException(404);
          } catch (Exception e) { // Other exceptions
              e.printStackTrace();
              throw new HTTPException(500);
          }
      }
  
  }
  </code></pre>
  
  <p>When I call the Rest Service with a code for which there are no results, the log message inside the <code>EntityNotFoundException</code> catch block is printed. However, my client receives a HTTP code 500 instead a 404. Why am I not receiving a 404 code?</p>
  
  <p>Thanks,</p>
  
  <p>Rafael Afonso</p>