You can make a class to encapsulate the response object like this:
class Error
{
public string Code { get; set; }
public string Description { get; set; }
public string Source { get; set; }
public string Step { get; set; }
public string Reason { get; set; }
public object Metadata { get; set; }
}
Then you can return a instance of that object like this:
[HttpGet]
public IActionResult SomeGetReq()
{
try
{
return Ok(someService.SomeMethod());
}
catch (Exception e)
{
// you can use e here
return BadRequest(new Error
{
Code = "BAD_REQUEST_ERROR",
Description = "frId is/are not required and should not be sent"
});
}
}