title: Extracting and displaying error message in Angular JS
body: <p>In Angular JS web app, if my rest API returns exception (un-handled thrown) how can I display the appropriate error to the front end.</p>
  
  <p>At the moment I am only able to display the generic error 'Error creating record.' but not able to retrieve the exact error message from the exception</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>    $http.post("/mdmservice/services/entity", $scope.entity).success(function(data, status, headers, config, statusText) {
          $scope.created=true;
          $scope.buttonsDisabled = true;          
          $scope.entityCreatedMessage = "New record created successfully.";
          $scope.error=false;
      }).error(function(data, status, headers, config, statusText ) {
          console.log("Error creating entity : " +data +"," +status +"," +headers +"," +config +"," +statusText);
          $scope.error=true;
          $scope.errorMessage="Error creating record.";
      });
  </code></pre>
  
  <p><strong>REST API</strong></p>
  
  <pre><code>    @POST
  @Path(value = "/create")
  @Consumes(value = MediaType.APPLICATION_JSON)
  @Override
  public Long create(Eentity entity) {
      Long entityId = null;
      entity.setEntityId(null);
      entity.setIsExcluded("N");
      try {
          // For create, the editIndicator=1
          entityId = entityBusiness.createOrUpdate(entity, 1);
      } catch (Exception e) {
          throw new WebApplicationException(e);
      }
      return entityId;
  }
  </code></pre>
  
  <p><strong>Exception log</strong></p>
  
  <pre><code>Caused by: com.jay.MyException: Entity code must be unique
          at com.jay.BusinessImpl.createOrUpdateEntity(EntityBusinessImpl.java:93)
          at com.jay.service.impl.EntityServiceImpl.createEntity(EntityServiceImpl.java:145)
          ... 38 more
  Caused by: com.jay.common.exception.EbaDataException: Entity code must be unique
          at com.jay.mdm.data.repository.jdbc.impl.EntityRepositoryJdbcImpl.createOrUpdateEntity(EntityRepositoryJdbcImpl.java:304)
          at com.jay.mdm.business.impl.EntityBusinessImpl.createOrUpdateEntity(EntityBusinessImpl.java:91)
          ... 39 more
  
  &lt;Dec 10, 2015 4:08:54 PM GMT&gt; &lt;Warning&gt; &lt;org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper&gt; &lt;BEA-000000&gt; &lt;javax.ws.rs.WebApplicationException: H
  TTP 500 Internal Server Error       
  </code></pre>