title: WebAPI Type of method that returns either Class or Error
body: <p>I'd want to ask about way to return errors when it comes to WebAPI</p>
  
  <p>I'm not sure whether I should use this approach, because this is not giving really good details except 500 internal server error code without UseDeveloperExceptionPage();</p>
  
  <pre><code>public async Task&lt;Token&gt; login(User creds)
  {
      var user = await Task.FromResult(_context.GetUser.....);
  
      if (user == null)
      {
          throw new Exception("Invalid credentials");
      }
  
      return BuildToken(user); // Task&lt;Token&gt;
  }
  
  public class Token
  {
      public string token { get; set; }
      public long Expires { get; set; }
  }
  </code></pre>
  
  <p>So, should I create dynamic json and cast Error model / my JWT model to that dynamic json or something like that?</p>
  
  <p>Basically I'd want to return either:</p>
  
  <pre><code>{
      "Token": "aaaaa.aaaaaaaaaa.aaaaaaaaaaa",
      "Expires": "111111111"
  }
      or
  {
      "message": "Invalid credentials"
  }
  </code></pre>