My API is returning a Byte array but if there's an error I need to return the status code and message but can't due to the return value is a Byte array. Where do I put the error message string?
public async Task<byte[]> GetPolicyPDF(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context)
{
byte[] ret = new byte[1024];
try
{
_log.LogInformation("C# HTTP trigger GetPolicyPDF processed a request.");
string effectiveDate = req.Query["EffectiveDate"].ToString();
string policyNumber = req.Query["PolicyNumber"].ToString();
string type = req.Query["Type"].ToString();
string contactId = req.Query["ContactID"].ToString();
//var contactOwnPolicy = await DataverseHelper.DoesContactOwnPolicy(context, contactId, policyNumber, _log);
//if (contactOwnPolicy == false)
// //return new ObjectResult($"Contact does not own Policy") { StatusCode = 500 };
// return ret;
//Process the request - pass everything that is needed
ret = await PolicyRequest.GetPolicyPDF(policyNumber, effectiveDate, type);
return ret;
}
catch (Exception ex)
{
return ret;
//return new ObjectResult($"{ex.Message}") { StatusCode = 500 };
}
}