title: Java Spring boot Internationalization for Default Spring error messages
body: <p>I'm working on internationalization on an existing Spring boot project, I've been having issues trying to figure out if default spring/spring boot errors can be converted automatically. </p>
  
  <p>I have it working for <code>MethodArgumentNotValidException</code> spring somehow converts it to the language specified in the request header</p>
  
  <pre><code>@ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
  public ResponseEntity&lt;Object&gt; handleBadRequest(MethodArgumentNotValidException ex, WebRequest request) {
      Locale locale = request.getLocale();
      ApiResponseEnvelope envelope = new ApiResponseEnvelope(false);
      BindingResult result = ex.getBindingResult();
      List&lt;FieldError&gt; errors = result.getFieldErrors();
  
      for (FieldError err : errors) {
          ApiError ae = new ApiError(messageSource.getMessage(err, locale), 44);
          envelope.addError(ae);
      }
  
      return new ResponseEntity(envelope, HttpStatus.BAD_REQUEST);
  }
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>{
      "success": false,
      "result": null,
      "errors": [
          {
              "message": "ne peut pas être nul",
              "code": 44
          },
          {
              "message": "ne peut pas être nul",
              "code": 44
          },
  .
  .
  .
  </code></pre>
  
  <p>But now for other exceptions that go through the <code>@ExceptionHandler(Exception.class)</code> handler it returns the exception as English. I believe somehow Spring should have a way of returning these generic errors in a localized language.</p>
  
  <p>Below the only way I can seem to convert an exception handled by the <code>Exception.class</code> handler is by reading from my messages file. Is there a way to handle these generic errors?</p>
  
  <pre><code>@ExceptionHandler(Exception.class)
  public ResponseEntity&lt;Object&gt; handleExceptions(Exception ex, Locale locale) {
      String errorMessage = attemptToFecthMessageForCode(ex,locale);
      //messageSource.getMessage(ExceptionProperty.UNEXPECTED_ERROR.getValue(), new Object[]{ex}, locale);
      //ex.printStackTrace();
      return new ResponseEntity&lt;&gt;(new RestMessage(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR);
  }
  
  public String attemptToFecthMessageForCode(Exception ex, Locale locale){
      String msg = ex.getMessage();
      try{
          msg = messageSource.getMessage(ex.getMessage(), ex.getStackTrace(), locale);
      }
      catch (Exception e){
          e.printStackTrace();
      }
  
      return msg;
  }
  </code></pre>
  
  <p>Thanks in advance!.</p>