sdk/dotnet/src/Microsoft.Datasync.Client/Http/ServiceHttpClient.cs
/// <summary>
/// When the server returns an error, the payload may contain the error message.  This
/// method will convert whatever the payload is into the appropriate error message.
/// </summary>
/// <param name="content">The payload, or <c>null</c> if there is no payload.</param>
/// <returns>The error message to use.</returns>
When the server returns an error, the payload may contain the error message.  This
method will convert whatever the payload is into the appropriate error message.
When the server returns an error the payload may contain the error message . This method will convert whatever the payload is into the appropriate error message .
private static string GetErrorMessageFromBody(string content)
        {
            if (string.IsNullOrWhiteSpace(content))
            {
                return null;
            }
            if (content[0] != '{')
            {
                return content;
            }
            JToken body = ParseOrDefault(content);
            if (body?.Type == JTokenType.Object)
            {
                JToken error = body["error"];
                if (error?.Type == JTokenType.String)
                {
                    return error.ToString();
                }
                JToken description = body["description"];
                if (description?.Type == JTokenType.String)
                {
                    return description.ToString();
                }
            }
            return null;
        }
private static string GetErrorMessageFromBody ( string content ) { if ( string . IsNullOrWhiteSpace ( content ) ) { return null ; } if ( content [ 0 ] != ' ' ) { return content ; } JToken body = ParseOrDefault ( content ) ; if ( body ? . Type == JTokenType . Object ) { JToken error = body [ " " ] ; if ( error ? . Type == JTokenType . String ) { return error . ToString ( ) ; } JToken description = body [ " " ] ; if ( description ? . Type == JTokenType . String ) { return description . ToString ( ) ; } } return null ; }
When the server returns an error, the payload may contain the error message.
When the server returns an error the payload may contain the error message .
// If it's not a JSON object, assume it's plain text
The error message to use.
The error message to use .
content
string
The payload, or null
The payload or null