Exemple #1
0
        /// <summary>
        /// Thrown when and error is received attempting to retrieve a token.
        /// </summary>
        /// <param name="apiToken"></param>
        /// <param name="response"></param>
        /// <param name="statusCode"></param>
        /// <param name="receivedAt"></param>
        public RequestGlobalXApiTokenErrorResponseException(
            GlobalXCredentials globalXCredentials,
            JObject response,
            HttpStatusCode statusCode,
            Instant receivedAt)
            : base(CreateDefaultMessage(globalXCredentials, statusCode, response))
        {
            GlobalXCredentials = globalXCredentials;
            StatusCode         = statusCode;
            ReceivedAt         = receivedAt;

            if (!(response is null))
            {
                Response    = response;
                RemoteError = response.Value <string>("error");
            }
        }
Exemple #2
0
        private static string CreateDefaultMessage(GlobalXCredentials globalXCredentials, HttpStatusCode httpStatusCode, JObject response)
        {
            var friendlyStatusCode = $"{(int)httpStatusCode} {httpStatusCode.ToString()}";

            if (response is null)
            {
                return($"GlobalX returned an error status code '{friendlyStatusCode}' when attempting to refresh the tokenSet for user '{globalXCredentials?.UserId}'. The response was empty.");
            }
            else
            {
                var remoteError            = response.Value <string>("error") ?? "null";
                var remoteErrorDescription = response.Value <string>("error_description") ?? "null";
                var remoteErrorUri         = response.Value <string>("error_uri") ?? "null";

                return($"GlobalX returned an error status code '{friendlyStatusCode}' when attempting to request a token from username and password." +
                       $", User ID : '{globalXCredentials?.UserId}'." +
                       $", Remote error:'{remoteError}'" +
                       $", error_description: '{remoteErrorDescription}'" +
                       $", and error_uri: '{remoteErrorUri}'");
            }
        }