Skip to content

Add Function to Check IsError(string json) #1

@an-d-uu

Description

@an-d-uu

I have been doing this in the application/project that uses the Utility.BaseClasses, but this would really be good to do within the library instead.

I would like to parse this without Newtonsoft due to the fact that it adds Newtonsoft as a dependancy.

public static Utility.BaseClasses.Error IsError(string json)
{
    Utility.BaseClasses.Error returnValue = new Utility.BaseClasses.Error();

    try
    {
        if (json.Contains("Message") && json.Contains("Status"))
        {
            returnValue = Newtonsoft.Json.JsonConvert.DeserializeObject<Utility.BaseClasses.Error>(json);
        }
    }
    catch
    {
        //suppressing the error because we are just using this as a checkpoint
        returnValue = new Utility.BaseClasses.Error();
    }

    return returnValue;
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions