@@ -18,10 +18,13 @@ public class DefaultSubmissionClient : ISubmissionClient, IDisposable {
18
18
private readonly HttpClient _client ;
19
19
20
20
public DefaultSubmissionClient ( ExceptionlessConfiguration config ) {
21
- _client = CreateHttpClient ( config ) ;
21
+ _client = CreateHttpClient ( config . UserAgent ) ;
22
22
}
23
23
24
24
public SubmissionResponse PostEvents ( IEnumerable < Event > events , ExceptionlessConfiguration config , IJsonSerializer serializer ) {
25
+ if ( ! config . IsValid )
26
+ return new SubmissionResponse ( 500 , message : "Invalid client configuration settings" ) ;
27
+
25
28
string data = serializer . Serialize ( events ) ;
26
29
string url = String . Format ( "{0}/events" , GetServiceEndPoint ( config ) ) ;
27
30
@@ -33,6 +36,7 @@ public SubmissionResponse PostEvents(IEnumerable<Event> events, ExceptionlessCon
33
36
if ( data . Length > 1024 * 4 )
34
37
content = new GzipContent ( content ) ;
35
38
39
+ _client . AddAuthorizationHeader ( config . ApiKey ) ;
36
40
response = _client . PostAsync ( url , content ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
37
41
} catch ( Exception ex ) {
38
42
return new SubmissionResponse ( 500 , message : ex . Message ) ;
@@ -46,6 +50,9 @@ public SubmissionResponse PostEvents(IEnumerable<Event> events, ExceptionlessCon
46
50
}
47
51
48
52
public SubmissionResponse PostUserDescription ( string referenceId , UserDescription description , ExceptionlessConfiguration config , IJsonSerializer serializer ) {
53
+ if ( ! config . IsValid )
54
+ return new SubmissionResponse ( 500 , message : "Invalid client configuration settings." ) ;
55
+
49
56
string data = serializer . Serialize ( description ) ;
50
57
string url = String . Format ( "{0}/events/by-ref/{1}/user-description" , GetServiceEndPoint ( config ) , referenceId ) ;
51
58
@@ -57,6 +64,7 @@ public SubmissionResponse PostUserDescription(string referenceId, UserDescriptio
57
64
if ( data . Length > 1024 * 4 )
58
65
content = new GzipContent ( content ) ;
59
66
67
+ _client . AddAuthorizationHeader ( config . ApiKey ) ;
60
68
response = _client . PostAsync ( url , content ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
61
69
} catch ( Exception ex ) {
62
70
return new SubmissionResponse ( 500 , message : ex . Message ) ;
@@ -69,11 +77,15 @@ public SubmissionResponse PostUserDescription(string referenceId, UserDescriptio
69
77
return new SubmissionResponse ( ( int ) response . StatusCode , GetResponseMessage ( response ) ) ;
70
78
}
71
79
72
- public SettingsResponse GetSettings ( ExceptionlessConfiguration config , int version , IJsonSerializer serializer ) {
80
+ public SettingsResponse GetSettings ( ExceptionlessConfiguration config , int version , IJsonSerializer serializer ) {
81
+ if ( ! config . IsValid )
82
+ return new SettingsResponse ( false , message : "Invalid client configuration settings." ) ;
83
+
73
84
string url = String . Format ( "{0}/projects/config?v={1}" , GetServiceEndPoint ( config ) , version ) ;
74
85
75
86
HttpResponseMessage response ;
76
87
try {
88
+ _client . AddAuthorizationHeader ( config . ApiKey ) ;
77
89
response = _client . GetAsync ( url ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
78
90
} catch ( Exception ex ) {
79
91
var message = String . Concat ( "Unable to retrieve configuration settings. Exception: " , ex . GetMessage ( ) ) ;
@@ -95,16 +107,20 @@ public SettingsResponse GetSettings(ExceptionlessConfiguration config, int versi
95
107
}
96
108
97
109
public void SendHeartbeat ( string sessionIdOrUserId , bool closeSession , ExceptionlessConfiguration config ) {
110
+ if ( ! config . IsValid )
111
+ return ;
112
+
98
113
string url = String . Format ( "{0}/events/session/heartbeat?id={1}&close={2}" , GetHeartbeatServiceEndPoint ( config ) , sessionIdOrUserId , closeSession ) ;
99
114
try {
115
+ _client . AddAuthorizationHeader ( config . ApiKey ) ;
100
116
_client . GetAsync ( url ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
101
117
} catch ( Exception ex ) {
102
118
var log = config . Resolver . GetLog ( ) ;
103
119
log . Error ( String . Concat ( "Error submitting heartbeat: " , ex . GetMessage ( ) ) ) ;
104
120
}
105
121
}
106
122
107
- private HttpClient CreateHttpClient ( ExceptionlessConfiguration config ) {
123
+ private HttpClient CreateHttpClient ( string userAgent ) {
108
124
#if ! NET45
109
125
var handler = new HttpClientHandler { UseDefaultCredentials = true } ;
110
126
@@ -123,9 +139,8 @@ private HttpClient CreateHttpClient(ExceptionlessConfiguration config) {
123
139
124
140
var client = new HttpClient ( handler , true ) ;
125
141
client . DefaultRequestHeaders . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
126
- client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( ExceptionlessHeaders . Bearer , config . ApiKey ) ;
127
142
client . DefaultRequestHeaders . ExpectContinue = false ;
128
- client . DefaultRequestHeaders . UserAgent . ParseAdd ( config . UserAgent ) ;
143
+ client . DefaultRequestHeaders . UserAgent . ParseAdd ( userAgent ) ;
129
144
130
145
return client ;
131
146
}
0 commit comments