title: C# custom error response for 424 and 422 error codes
body: <p>I want to be able to return Status code - 424(Failed Dependency) and 422(Unprocessable Entity) from my API. We are using a custom error handlers to handle the error responses as follows:</p>
  <pre><code>public class ApiResponse
  {
      public string StatusCode { get; set; }
      public string Message { get; set; }
      public ApiResponse(int statusCode, string message = null)
      {
          StatusCode = GetDefaultMessageForStatusCode(statusCode);
          Message = message;
      }
      private static string GetDefaultMessageForStatusCode(int statusCode)
      {
          switch (statusCode)
          {
              case 200:
                  return &quot;Success.&quot;;
              case 400:
                  return &quot;Bad request.&quot;;
              case 404:
                  return &quot;Not Found.&quot;;
              case 424:
                  return &quot;Dependency Failure&quot;;
              case 500:
                  return &quot;An unhandled error occurred.&quot;;
              default:
                  return null;
          }
      }
  }
  
  public class DependencyFailureResponse : ApiResponse
  {
      public DependencyFailureResponse(string message) : base(424)
      {
          Message = message;
      }
  }
  </code></pre>
  <p>When I call the DependencyFailureResponse from my controller I am getting the &quot;Dependency Failure&quot; status code along with my custom message. But, as I am calling it as -</p>
  <pre><code>return BadRequest(new DependencyFailureResponse(&quot;Custom message&quot;));
  </code></pre>
  <p>it will be always shown as 400 Bad Request.</p>
  <p>I want to be able to call it in such a way that &quot;400 Bad Request&quot; should not be shown.</p>