<commit_before>﻿// Copyright (c) <NAME> & <NAME>. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using Newtonsoft.Json.Linq;
using System;
using System.Net;

namespace IdentityModel.Client
{
    public class TokenRevocationResponse
    {
        public string Raw { get; }
        public JObject Json { get; }
        public bool IsError { get; }
        public HttpStatusCode HttpStatusCode { get; }
        public string HttpErrorReason { get; }
        public ResponseErrorType ErrorType { get;  }
        public Exception Exception { get;  }

        public TokenRevocationResponse()
        {
            IsError = false;
        }

        public TokenRevocationResponse(string raw)
        {
            Raw = raw;
            IsError = false;
            HttpStatusCode = HttpStatusCode.OK;

            try
            {
                Json = JObject.Parse(raw);
            }
            catch (Exception ex)
            {
                IsError = true;
                ErrorType = ResponseErrorType.Exception;
                Exception = ex;
            }
        }

        public TokenRevocationResponse(HttpStatusCode statusCode, string reason)
        {
            IsError = true;

            ErrorType = ResponseErrorType.Http;
            HttpStatusCode = statusCode;
            HttpErrorReason = reason;
        }

        public TokenRevocationResponse(Exception exception)
        {
            IsError = true;

            Exception = exception;
            ErrorType = ResponseErrorType.Exception;
        }

        public string Error
        {
            get
            {
                if (ErrorType == ResponseErrorType.Http)
                {
                    return HttpErrorReason;
                }
                else if(ErrorType == ResponseErrorType.Exception)
                {
                    return Exception.Message;
                }

                return GetStringOrNull(OidcConstants.TokenResponse.Error);
            }
        }

        protected virtual string GetStringOrNull(string name)
        {
            JToken value;
            if (Json != null && Json.TryGetValue(name, StringComparison.OrdinalIgnoreCase, out value))
            {
                return value.ToString();
            }

            return null;
        }
    }
}<commit_msg>fixed another bug in TokenRevocationResponse<commit_after>﻿// Copyright (c) <NAME> & <NAME>. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using Newtonsoft.Json.Linq;
using System;
using System.Net;

namespace IdentityModel.Client
{
    public class TokenRevocationResponse
    {
        public string Raw { get; }
        public JObject Json { get; }
        public bool IsError { get; }
        public HttpStatusCode HttpStatusCode { get; }
        public string HttpErrorReason { get; }
        public ResponseErrorType ErrorType { get;  }
        public Exception Exception { get;  }

        public TokenRevocationResponse()
        {
            IsError = false;
        }

        public TokenRevocationResponse(string raw)
        {
            Raw = raw;
            IsError = false;
            HttpStatusCode = HttpStatusCode.OK;

            try
            {
                Json = JObject.Parse(raw);

                if (!string.IsNullOrEmpty(Json.TryGetString(OidcConstants.TokenResponse.Error)))
                {
                    IsError = true;
                }
            }
            catch (Exception ex)
            {
                IsError = true;
                ErrorType = ResponseErrorType.Exception;
                Exception = ex;
            }
        }

        public TokenRevocationResponse(HttpStatusCode statusCode, string reason)
        {
            IsError = true;

            ErrorType = ResponseErrorType.Http;
            HttpStatusCode = statusCode;
            HttpErrorReason = reason;
        }

        public TokenRevocationResponse(Exception exception)
        {
            IsError = true;

            Exception = exception;
            ErrorType = ResponseErrorType.Exception;
        }

        public string Error
        {
            get
            {
                if (ErrorType == ResponseErrorType.Http)
                {
                    return HttpErrorReason;
                }
                else if(ErrorType == ResponseErrorType.Exception)
                {
                    return Exception.Message;
                }

                return Json.TryGetString(OidcConstants.TokenResponse.Error);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.06777493606138107, 'fraction_numerical': 0.0008525149190110827, 'mean_word_length': 1.4203197524497164, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3395979', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1077, 'n_words': 278}