Return a StringContent to client to show a message

264 Views Asked by At

I have a rest service, and I must do a get that can return one or zero objects.. Here the object I return if I find it:

public class FollowXMessage
{
    public string UploadFolder { get; set; }
    public int Status { get; set; }
    public int CustomerType{ get; set; }
}

If I find an object I can return correctly it to the client... If I do not find anything I would like to return a message that advice the user that nothing has been found:

if (found)
{
    ...
    return Ok(result); //result is FollowXMessage
}
else if (!found)
{
    return Ok(new StringContent("Nothing Found", System.Text.Encoding.UTF8, "text/plain"));
}

//In all other cases there has been raised an exception
return BadRequest("Some errors");

Client side I thought to manage the result in this way:

var successCallback = function (response)
{
    if(typeof response == "string")
        //show message
    else
        //do something             
};

The problem is that I never receive a string... If no object is returned I receive this response:

enter image description here

Where is my message "Nothing Found"?

Thank you

0

There are 0 best solutions below