• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Jericho / ZoomNet / 704

05 Apr 2024 11:26PM UTC coverage: 20.198% (+0.7%) from 19.504%
704

push

appveyor

Jericho
Merge branch 'release/0.75.0'

613 of 3035 relevant lines covered (20.2%)

12.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.92
/Source/ZoomNet/Utilities/ZoomErrorHandler.cs
1
using Pathoschild.Http.Client;
2
using Pathoschild.Http.Client.Extensibility;
3
using System.Net;
4

5
namespace ZoomNet.Utilities
6
{
7
        /// <summary>
8
        /// Error handler for requests dispatched to the Zoom API.
9
        /// </summary>
10
        /// <seealso cref="Pathoschild.Http.Client.Extensibility.IHttpFilter" />
11
        internal class ZoomErrorHandler : IHttpFilter
12
        {
13
                private const string DEFAULT_HTTP_200_EXCEPTION_MESSAGE = "The Zoom API returned a status code that indicates that your request was unseccessful, without providing an explanation. Typically this means that you either lack the necessary permissions or that a paid account is required and you have a free account.";
14

15
                /// <summary>
16
                /// Gets or sets a value indicating whether HTTP 200 returned by the Zoom API should be treated as a failure.
17
                /// </summary>
18
                /// <remarks>
19
                /// As incredible as it sounds, Zoom sometimes uses HTTP 200 to indicate that a particular request has failed.
20
                /// One such example is when you attempt to update a webinar but your account does not have a Webinar subscription plan. See the <a href="https://marketplace.zoom.us/docs/api-reference/zoom-api/webinars/webinarupdate#responses">'Responses' section in the documentation about updating a webinar</a>.
21
                /// Another example is when you attempt to create a role but you do not have the permission to do so. See the <a href="https://marketplace.zoom.us/docs/api-reference/zoom-api/roles/createrole#responses">'Responses' section in the documentation about creating a role</a>.
22
                /// </remarks>
23
                public bool TreatHttp200AsException { get; set; }
24

25
                /// <summary>
26
                /// Gets or sets a custom error message used when the Zom API returns a HTTP 200 status code that is treated as a failure.
27
                /// </summary>
28
                /// <remarks>
29
                /// A generic message is used if you do not provide your own custom message.
30
                /// </remarks>
31
                public string CustomHttp200ExceptionMessage { get; set; }
32

33
                public ZoomErrorHandler()
34
                        : this(false, null) { }
14✔
35

36
                public ZoomErrorHandler(bool treatHttp200AsException, string customHttp200ExceptionMessage)
37
                {
38
                        TreatHttp200AsException = treatHttp200AsException;
7✔
39
                        CustomHttp200ExceptionMessage = customHttp200ExceptionMessage;
7✔
40
                }
7✔
41

42
                #region PUBLIC METHODS
43

44
                /// <summary>Method invoked just before the HTTP request is submitted. This method can modify the outgoing HTTP request.</summary>
45
                /// <param name="request">The HTTP request.</param>
46
                public void OnRequest(IRequest request) { }
6✔
47

48
                /// <summary>Method invoked just after the HTTP response is received. This method can modify the incoming HTTP response.</summary>
49
                /// <param name="response">The HTTP response.</param>
50
                /// <param name="httpErrorAsException">Whether HTTP error responses should be raised as exceptions.</param>
51
                public void OnResponse(IResponse response, bool httpErrorAsException)
52
                {
53
                        var (isError, errorMessage, errorCode) = response.Message.GetErrorMessageAsync().GetAwaiter().GetResult();
6✔
54
                        var diagnosticLog = response.GetDiagnosticInfo()?.GetFormattedLog() ?? "Diagnostic log unavailable";
6✔
55

56
                        if (TreatHttp200AsException && response.Status == HttpStatusCode.OK)
6✔
57
                        {
58
                                // We favor the custom message provided by developer or the message in the response from Zoom.
59
                                // If both of these messages are null, we fallback on a generic message.
60
                                errorMessage = CustomHttp200ExceptionMessage ?? errorMessage ?? DEFAULT_HTTP_200_EXCEPTION_MESSAGE;
×
61

62
                                throw new ZoomException(errorMessage, response.Message, diagnosticLog);
×
63
                        }
64
                        else if (!isError)
6✔
65
                        {
66
                                return;
6✔
67
                        }
68

69
                        throw new ZoomException(errorMessage, response.Message, diagnosticLog, errorCode);
×
70
                }
71

72
                #endregion
73
        }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc