Tuesday, April 30, 2019

Don't hand to the JsonResult of the Microsoft.AspNetCore.Mvc namespace stringified JSON in C#.

When you parse the string in JS you may get a string for the object instead of an object. This for example is bad. Instead, do stuff like this:

  1. context.Result = new JsonResult(new { Message = context.Exception.Message });
     
  2. string message = "An error at the API occurred. The specific error message is
          being hidden from what the API exposes for security. If you have access to the
          logs you may see a better description free from obfuscation therein.";
    context.Result = new JsonResult(new { Message = message });

No comments:

Post a Comment