title: Mapping WebApplicationExceptions
body: <p>I am wondering what the proper use is for the Javax-RS/Jersey <code>ExceptionMapper</code> class when it comes to mapping <code>WebApplicationExceptions</code></p>
  
  <p>I like the following, simple, 3-status paradigm:</p>
  
  <ul>
  <li>HTTP 200 OK indicates successful response, no errors at all whatsoever; and</li>
  <li>HTTP 404 indicates client-side error; and</li>
  <li>HTTP 500 indicates server-side error</li>
  </ul>
  
  <p>The problem with <code>WebApplicationExceptions</code> is that they could either be client-side (403, Forbidden) or server-side (503 Bad Gateway); hence they might map to a 404 or 500 depending on the situation.</p>
  
  <p><strong>I'm struggling with trying to inspect <code>WebApplicationException</code> so that I can determine whether its client- or server-side.</strong></p>
  
  <p>My best attempt thus far:</p>
  
  <pre><code>// Groovy pseudo-code
  class MyMapper implements ExceptionMapper&lt;Throwable&gt; {
      @Override
      Response toResponse(Throwable error) {
          if(error instanceof WebApplicationException) {
              if(isClientSide(error as WebApplicationException)) {
                  // Return HTTP 404.
              } else {
                  // Return HTTP 500.
              }
          } else if(error instanceof ClientException) {
              // Return HTTP 404.
          } else if(error instanceof ServerException) {
              // Return HTTP 500.
          } else {
              // All other throwables. Default to HTTP 500.
          }
      }
  
      private boolean isClientSide(WebApplicationException webAppExc) {
          // TODO: How to make this determination?
      }
  }
  </code></pre>
  
  <p>So a few concerns/issues here:</p>
  
  <ul>
  <li>Will this <code>ExceptionMapper</code> really catch <em>all</em> <code>Throwables</code> (every <code>Exception</code> and <code>Error</code> subclass), or just <code>Throwables</code>?; and</li>
  <li>What can I do inside <code>isClientSide(...)</code> to determine whether the error thrown was client- or server-side in origin? Let's pretend that a <code>WebApplicationException</code> created with a status of <code>FORBIDDEN</code> should be considered "client-side", but one created with a status of <code>BAD_GATEWAY</code> should not be.</li>
  </ul>