Exemplo n.º 1
0
 private static IllegalApiResponseException GetInvalidAccessTokenException(OmniKassaErrorResponse response)
 {
     if (response.ErrorMessage != null)
     {
         return(new InvalidAccessTokenException(response.ErrorMessage));
     }
     return(new InvalidAccessTokenException());
 }
Exemplo n.º 2
0
        /// <summary>
        /// Helper function to initialize an IllegalApiResponseException by parsing the JSON
        /// </summary>
        /// <param name="json">JSON containing the API error</param>
        /// <returns>New instance of IllegalApiResponseException</returns>
        public static IllegalApiResponseException Of(String json)
        {
            OmniKassaErrorResponse response = JsonConvert.DeserializeObject <OmniKassaErrorResponse>(json);

            if (response.ErrorCode == InvalidAccessTokenException.INVALID_AUTHORIZATION_ERROR_CODE)
            {
                if (response.ConsumerMessage != null &&
                    response.ConsumerMessage.ToLower().Equals("invalid or missing signature"))
                {
                    return(new IllegalSignatureException(response.ErrorCode, response.ConsumerMessage));
                }
                else
                {
                    return(GetInvalidAccessTokenException(response));
                }
            }

            if (response.ConsumerMessage != null)
            {
                return(new IllegalApiResponseException(response.ErrorCode, response.ConsumerMessage));
            }
            return(new IllegalApiResponseException(response.ErrorCode));
        }