title: Angularjs - Spring MVC Rest : how to handle exceptions
body: <p>I am developping an single page app with angularjs and Spring Mcv Rest.<br>
  I am calling my service (mail sending with javax mail) like that in Angularjs : <code>SendProformaFax.get({idCommande:$scope.commande.id})</code></p>
  
  <p>And on server side my service : </p>
  
  <pre><code>@RequestMapping(value = "/sendProformaFax/{idCommande}",
              method = RequestMethod.GET,
              produces = MediaType.APPLICATION_JSON_VALUE)
      @Timed
      public void imprimeProforma(@PathVariable String idCommande) {
          Commande commande = commandeRepository.findOne(new Long(idCommande));
          List&lt;Vente&gt; ventes = venteRepository.findAllByCommande(commande);
          blService.sendProformaFax(ventes);
     }
  </code></pre>
  
  <p>I would like to display a message when the function sendProformaFax throws a MessagingException.</p>
  
  <p>I don't know how to return this exception in my RestController and how to catch it in Angularjs.</p>
  
  <p>If anyone can help me on this...<br>
  Thanks.</p>
  
  <p>EDIT : 
  On server side I am doing this :</p>
  
  <pre><code>@ExceptionHandler(value = Exception.class)
      public ErrorView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
          // If the exception is annotated with @ResponseStatus rethrow it and let
          // the framework handle it - like the OrderNotFoundException example
          // at the start of this post.
          // AnnotationUtils is a Spring Framework utility class.
          if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null)
              throw e;
  
          // Otherwise setup and send the user to a default error-view.
          ErrorView mav = new ErrorView();
          mav.setException(e.getMessage());
          mav.setUrl(req.getRequestURL().toString());
          mav.setMessage("Veuillez contacter le support informatique.");
          return mav;
      }
  </code></pre>
  
  <p>On Angularjs side I am doing this</p>
  
  <pre><code>CreateFichierCiel.get({params:param}, function (response) {
                  $scope.infoMessage = "La génération du fichier CIEL est terminée."
                  $activityIndicator.stopAnimating();
                  $("#messageModal").modal('show');
                  $scope.find();
              }, function (reason) {
                  $("#errorModal").modal('show');
              }) 
  </code></pre>
  
  <p>But 'reason' object is like this :</p>
  
  <blockquote>
    <p>config: Object data: Object error: "Internal Server Error" exception:
    "java.lang.NullPointerException" message: "No message available" path:
    "/api/createFichierCiel/15-00005" status: 500 timestamp: 1438430232307
    proto: Object headers: function (name) { status: 500 statusText:
    "Internal Server Error" proto: Object</p>
  </blockquote>
  
  <p>So I am not getting the ErrorView class sent from the server.
  If anyone can see where I am wrong here...</p>
  
  <p>Thanks</p>