title: How do I return a 401 authentication error to a RestSharp client?
body: <p>In my Mvc Api controller, if the user cannot be authenticated I throw an HttpException 401.  However, the RestSharp client seems to translate this into a Http 500 status code.</p>
  
  <p>I want to be able to throw HttpExceptions from my Mvc controller, and have the RestSharp client preserve the original error in its StatusCode property.</p>
  
  <p>Also, I notice if the server is not up, when the RestSharp client makes a request, the reponse has a status code of 0, and a response code of Error.  Should the RestSharp not return a 404 http error code instead?</p>
  
  <p>What I really need is a bit of documentation on how RestSharp works with HttpCodes.</p>
  
  <p>Updated with code in my api controller:</p>
  
  <pre><code>throw new HttpException((int)HttpStatusCode.Unauthorized, AuthenticationError);
  </code></pre>