title: Handling error ASP.NET Web API
body: <p>I am creating an ASP.NET Web API method. The web method accepts four input parameters which are used in querying an Oracle Database and returns the result in JSON. The input parameters are of type string and DateTime. The API call looks like <code>?id=123&amp;date_in=01-JAN-16</code>. In the controller I have to handle validation errors such as id is null in the API call or the date format is different other than dd-MMM-yy and return an appropriate error message.</p>
  
  <pre><code>public class DataController : ApiController
  {
      [HttpGet]
      public HttpResponseMessage Getdetails(string id,DateTime date_in)
          {
              List&lt;OracleParameter&gt; prms = new List&lt;OracleParameter&gt;();
              prms.Add(new OracleParameter("id", OracleDbType.Varchar2, id, ParameterDirection.Input));
              prms.Add(new OracleParameter("date_in", OracleDbType.Date, date_in, ParameterDirection.Input));
             string connStr = ConfigurationManager.ConnectionStrings["DtConnection"].ConnectionString;
          using (OracleConnection dbconn = new OracleConnection(connStr))
          {
              DataSet userDataset = new DataSet();
              var strQuery = "SELECT * from SAMPLE where id = :id and date_in = :date_in ";
              var returnObject = new { data = new OracleDataTableJsonResponse(connStr, strQuery, prms.ToArray()) };
              var response = Request.CreateResponse(HttpStatusCode.OK, returnObject, MediaTypeHeaderValue.Parse("application/json"));
              ContentDispositionHeaderValue contentDisposition = null;
              if (ContentDispositionHeaderValue.TryParse("inline; filename=TGSData.json", out contentDisposition))
              {
                  response.Content.Headers.ContentDisposition = contentDisposition;
              }
              return response;
  </code></pre>
  
  <p>Should I create a different class for handling these exceptions? How should I be returning the responses?</p>