コード例 #1
0
        /// <summary>
        ///     Constructs new <see cref="LykkeApiErrorException" />.
        /// </summary>
        /// <param name="httpStatusCode">Http status code.</param>
        /// <param name="lykkeApiErrorCode">
        ///     Error code identifying what kind of error happened.
        /// </param>
        /// <param name="message">Message to include in response.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="lykkeApiErrorCode" /> is null.
        /// </exception>
        private LykkeApiErrorException(HttpStatusCode httpStatusCode, ILykkeApiErrorCode lykkeApiErrorCode,
                                       string message) : base(GetMessage(lykkeApiErrorCode, message))
        {
            LykkeApiErrorCode = lykkeApiErrorCode ?? throw new ArgumentNullException(nameof(lykkeApiErrorCode));

            StatusCode = httpStatusCode;
        }
コード例 #2
0
        private static string GetMessage(ILykkeApiErrorCode lykkeApiErrorCode, string message)
        {
            if (lykkeApiErrorCode == null)
            {
                throw new ArgumentNullException(nameof(lykkeApiErrorCode));
            }

            if (string.IsNullOrEmpty(message))
            {
                return(lykkeApiErrorCode.DefaultMessage ?? string.Empty);
            }

            return(message);
        }
コード例 #3
0
 /// <summary>
 ///     Create a 403 forbidden api error.
 /// </summary>
 /// <param name="lykkeApiErrorCode">
 ///     Error code identifying what kind of error happened.
 /// </param>
 /// <param name="message">Message to include in response.</param>
 /// <returns>
 ///     New <see cref="LykkeApiErrorException" /> with <see cref="StatusCode" /> set to
 ///     <see cref="HttpStatusCode.Forbidden" />.
 /// </returns>
 public static LykkeApiErrorException Forbidden(ILykkeApiErrorCode lykkeApiErrorCode,
                                                string message = "")
 {
     return(new LykkeApiErrorException(HttpStatusCode.Forbidden, lykkeApiErrorCode, message));
 }
コード例 #4
0
 /// <summary>
 ///     Create a 404 not found api error.
 /// </summary>
 /// <param name="lykkeApiErrorCode">
 ///     Error code identifying what kind of error happened.
 /// </param>
 /// <param name="message">Message to include in response.</param>
 /// <returns>
 ///     New <see cref="LykkeApiErrorException" /> with <see cref="StatusCode" /> set to
 ///     <see cref="HttpStatusCode.NotFound" />.
 /// </returns>
 public static LykkeApiErrorException NotFound(ILykkeApiErrorCode lykkeApiErrorCode,
                                               string message = "")
 {
     return(new LykkeApiErrorException(HttpStatusCode.NotFound, lykkeApiErrorCode, message));
 }
コード例 #5
0
 /// <summary>
 ///     Create a 400 bad request api error.
 /// </summary>
 /// <param name="lykkeApiErrorCode">
 ///     Error code identifying what kind of error happened.
 /// </param>
 /// <param name="message">Message to include in response.</param>
 /// <returns>
 ///     New <see cref="LykkeApiErrorException" /> with <see cref="StatusCode" /> set to
 ///     <see cref="HttpStatusCode.BadRequest" />.
 /// </returns>
 public static LykkeApiErrorException BadRequest(ILykkeApiErrorCode lykkeApiErrorCode,
                                                 string message = "")
 {
     return(new LykkeApiErrorException(HttpStatusCode.BadRequest, lykkeApiErrorCode, message));
 }
コード例 #6
0
 /// <summary>
 ///     Create a 401 Unauthorized error
 /// </summary>
 /// <param name="lykkeApiErrorCode">
 ///     Error code identifying what kind of error happened.</param>
 /// <param name="message">
 ///     Message to include in response.</param>
 /// <returns>
 ///     New <see cref="LykkeApiErrorException" /> with <see cref="StatusCode" /> set to
 ///     <see cref="HttpStatusCode.Unauthorized" />.
 /// </returns>
 public static LykkeApiErrorException Unauthorized(ILykkeApiErrorCode lykkeApiErrorCode,
                                                   string message = "")
 {
     return(new LykkeApiErrorException(HttpStatusCode.Unauthorized, lykkeApiErrorCode, message));
 }