summaryrefslogtreecommitdiff
path: root/dsa/FireBase/FirebaseException.cs
blob: f74c54e3bed33d570ff13b0ce80318710e390c0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Net;

namespace Firebase.Database {
    public class FirebaseException : Exception {
        public FirebaseException(string requestUrl, string requestData, string responseData, HttpStatusCode statusCode)
            : base(GenerateExceptionMessage(requestUrl, requestData, responseData)) {
            RequestUrl = requestUrl;
            RequestData = requestData;
            ResponseData = responseData;
            StatusCode = statusCode;
        }

        public FirebaseException(string requestUrl, string requestData, string responseData, HttpStatusCode statusCode,
            Exception innerException)
            : base(GenerateExceptionMessage(requestUrl, requestData, responseData), innerException) {
            RequestUrl = requestUrl;
            RequestData = requestData;
            ResponseData = responseData;
            StatusCode = statusCode;
        }

        /// <summary>
        ///     Post data passed to the authentication service.
        /// </summary>
        public string RequestData { get; }

        /// <summary>
        ///     Original url of the request.
        /// </summary>
        public string RequestUrl { get; }

        /// <summary>
        ///     Response from the authentication service.
        /// </summary>
        public string ResponseData { get; }

        /// <summary>
        ///     Status code of the response.
        /// </summary>
        public HttpStatusCode StatusCode { get; }

        private static string GenerateExceptionMessage(string requestUrl, string requestData, string responseData) {
            return
                $"Exception occured while processing the request.\nUrl: {requestUrl}\nRequest Data: {requestData}\nResponse: {responseData}";
        }
    }
}