Esempio n. 1
0
        /// <summary>
        /// Attempts to extract a <see cref="MatrixError" /> from an <see cref="ApiException" />.
        /// </summary>
        /// <param name="exception">The exception instance to extract an error from.</param>
        /// <param name="error">
        /// When this method returns, contains the extracted error, if one was found; otherwise,
        /// the default value for <see cref="MatrixError" />.
        /// </param>
        /// <returns><c>true</c> if an error was found; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="exception" /> is <c>null</c>.</exception>
        public static bool TryGetError([NotNull] this ApiException exception, out MatrixError error)
        {
            if (exception == null)
            {
                throw new ArgumentNullException(nameof(exception));
            }

            try
            {
                error = exception.GetError();
                return(true);
            }
            catch (JsonSerializationException)
            {
                error = default;
                return(false);
            }
        }