Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
HttpClientErrorFormatter.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#include "../Common/ResultErrorFormatter.h"
6#include "HttpClientError.h"
7
8namespace SC
9{
12inline ResultErrorFormat formatHttpClientError(HttpClientError error, Span<char> output)
13{
14 ResultErrorFormatter formatter(output);
15 switch (error)
16 {
17 case HttpClientError::RequestHeaderNameEmpty: formatter.append("HTTP client request header name is empty"); break;
18 case HttpClientError::RequestHeaderNameInvalid:
19 formatter.append("HTTP client request header name is invalid");
20 break;
21 case HttpClientError::RequestHeaderValueInvalid:
22 formatter.append("HTTP client request header value is invalid");
23 break;
24 case HttpClientError::RequestTransferEncodingForbidden:
25 formatter.append("HTTP client request Transfer-Encoding is controlled by body framing");
26 break;
27 case HttpClientError::RequestChunkedContentLengthConflict:
28 formatter.append("HTTP client chunked request body cannot use Content-Length");
29 break;
30 case HttpClientError::RequestFixedBodyProviderUnexpected:
31 formatter.append("HTTP client fixed request body cannot use a provider");
32 break;
33 case HttpClientError::RequestFixedBodySizeMismatch:
34 formatter.append("HTTP client fixed request body size does not match its bytes");
35 break;
36 case HttpClientError::RequestStreamInlineBytesUnexpected:
37 formatter.append("HTTP client streamed request body cannot use inline bytes");
38 break;
39 case HttpClientError::RequestStreamProviderMissing:
40 formatter.append("HTTP client streamed request body requires a provider");
41 break;
42 case HttpClientError::RequestChunkedDeclaredSizeInvalid:
43 formatter.append("HTTP client chunked request body cannot declare a fixed size");
44 break;
45 case HttpClientError::RequestBodyFramingInvalid:
46 formatter.append("HTTP client request body framing is invalid");
47 break;
48 case HttpClientError::RequestUrlEmpty: formatter.append("HTTP client request URL is empty"); break;
49 case HttpClientError::RequestUrlUnsafe:
50 formatter.append("HTTP client request URL contains whitespace or control bytes");
51 break;
52 case HttpClientError::RequestUrlSchemeUnsupported:
53 formatter.append("HTTP client request URL must use HTTP or HTTPS");
54 break;
55 case HttpClientError::RequestUrlHostEmpty: formatter.append("HTTP client request URL host is empty"); break;
56 case HttpClientError::RequestMethodInvalid: formatter.append("HTTP client request method is invalid"); break;
57 case HttpClientError::RequestRedirectModeInvalid: formatter.append("HTTP client redirect mode is invalid"); break;
58 case HttpClientError::RequestProtocolPreferenceInvalid:
59 formatter.append("HTTP client protocol preference is invalid");
60 break;
61 case HttpClientError::RequestTlsCaPathInvalid:
62 formatter.append("HTTP client TLS CA path contains control bytes");
63 break;
64 case HttpClientError::RequestRedirectMethodInvalid:
65 formatter.append("HTTP client redirect policy requires GET or HEAD");
66 break;
67 case HttpClientError::RequestRedirectBodyNotReplayable:
68 formatter.append("HTTP client automatic redirects require a replayable request body");
69 break;
70 case HttpClientError::ProxyModeInvalid: formatter.append("HTTP client proxy mode is invalid"); break;
71 case HttpClientError::ProxyUrlEmpty: formatter.append("HTTP client proxy URL is empty"); break;
72 case HttpClientError::ProxyUrlSchemeUnsupported: formatter.append("HTTP client proxy URL must use HTTP"); break;
73 case HttpClientError::ProxyUrlUnsafe:
74 formatter.append("HTTP client proxy URL contains whitespace or control bytes");
75 break;
76 case HttpClientError::ProxyUrlHostEmpty: formatter.append("HTTP client proxy URL host is empty"); break;
77 case HttpClientError::ProxyUrlPathUnsupported:
78 formatter.append("HTTP client proxy URL must not include a path, query, or fragment");
79 break;
80 case HttpClientError::ProxyAuthorizationInvalid:
81 formatter.append("HTTP client proxy authorization contains invalid bytes");
82 break;
83 case HttpClientError::ProxyBypassListInvalid:
84 formatter.append("HTTP client proxy bypass list contains invalid bytes");
85 break;
86 case HttpClientError::ProxyUrlWithoutHttpMode:
87 formatter.append("HTTP client proxy URL requires HTTP proxy mode");
88 break;
89 case HttpClientError::ProxyAuthorizationWithoutHttpMode:
90 formatter.append("HTTP client proxy authorization requires HTTP proxy mode");
91 break;
92 case HttpClientError::ProxyBypassListWithoutHttpMode:
93 formatter.append("HTTP client proxy bypass list requires HTTP proxy mode");
94 break;
95 case HttpClientError::RedirectPolicyUnsupported:
96 formatter.append("HTTP client redirect policy is unsupported");
97 break;
98 case HttpClientError::Http11OnlyUnsupported:
99 formatter.append("HTTP client HTTP/1.1-only policy is unsupported");
100 break;
101 case HttpClientError::Http2PreferredUnsupported:
102 formatter.append("HTTP client HTTP/2 preference is unsupported");
103 break;
104 case HttpClientError::Http2RequiredUnsupported:
105 formatter.append("HTTP client required HTTP/2 policy is unsupported");
106 break;
107 case HttpClientError::TlsDisablePeerVerificationUnsupported:
108 formatter.append("HTTP client disabling TLS peer verification is unsupported");
109 break;
110 case HttpClientError::TlsCustomCaPathUnsupported:
111 formatter.append("HTTP client custom TLS CA path is unsupported");
112 break;
113 case HttpClientError::NoProxyPolicyUnsupported:
114 formatter.append("HTTP client no-proxy policy is unsupported");
115 break;
116 case HttpClientError::HttpProxyPolicyUnsupported:
117 formatter.append("HTTP client HTTP proxy policy is unsupported");
118 break;
119 case HttpClientError::ProxyAuthorizationUnsupported:
120 formatter.append("HTTP client proxy authorization is unsupported");
121 break;
122 case HttpClientError::ProxyBypassListUnsupported:
123 formatter.append("HTTP client proxy bypass list is unsupported");
124 break;
125 case HttpClientError::RequiredBackendUnavailable:
126 formatter.append("HTTP client required backend is unavailable");
127 break;
128 case HttpClientError::RequiredFeatureUnsupported:
129 formatter.append("HTTP client required feature is unsupported");
130 break;
131 case HttpClientError::ClientAlreadyInitialized: formatter.append("HTTP client is already initialized"); break;
132 case HttpClientError::OperationClientNotInitialized:
133 formatter.append("HTTP client operation requires an initialized client");
134 break;
135 case HttpClientError::OperationAlreadyInitialized:
136 formatter.append("HTTP client operation is already initialized");
137 break;
138 case HttpClientError::ResponseBuffersMissing: formatter.append("HTTP client response buffers are missing"); break;
139 case HttpClientError::ResponseBufferMemoryTooSmall:
140 formatter.append("HTTP client response buffer memory is too small");
141 break;
142 case HttpClientError::ResponseBufferEmpty: formatter.append("HTTP client response buffer is empty"); break;
143 case HttpClientError::OperationEventQueueMissing:
144 formatter.append("HTTP client operation event queue is missing");
145 break;
146 case HttpClientError::OperationResponseHeadersMissing:
147 formatter.append("HTTP client operation response header storage is missing");
148 break;
149 case HttpClientError::OperationResponseMetadataMissing:
150 formatter.append("HTTP client operation response metadata storage is missing");
151 break;
152 case HttpClientError::OperationNotInitialized: formatter.append("HTTP client operation is not initialized"); break;
153 case HttpClientError::OperationRequestInFlight:
154 formatter.append("HTTP client operation already has a request in flight");
155 break;
156 case HttpClientError::RequestBodyDestinationEmpty:
157 formatter.append("HTTP client request body destination is empty");
158 break;
159 case HttpClientError::RequestBodyProviderOverflow:
160 formatter.append("HTTP client request body provider exceeded its destination");
161 break;
162 case HttpClientError::RequestBodyProviderStalled:
163 formatter.append("HTTP client request body provider made no progress");
164 break;
165 case HttpClientError::RequestBodyDeclaredSizeExceeded:
166 formatter.append("HTTP client request body exceeded its declared size");
167 break;
168 case HttpClientError::RequestBodyDeclaredSizeIncomplete:
169 formatter.append("HTTP client request body ended before its declared size");
170 break;
171 case HttpClientError::ResponseBufferCapacityInsufficient:
172 formatter.append("HTTP client response buffer cannot hold the requested data");
173 break;
174 case HttpClientError::RequestCancelled: formatter.append("HTTP client request was cancelled"); break;
175 case HttpClientError::ResponseBufferIndexInvalid:
176 formatter.append("HTTP client response buffer index is invalid");
177 break;
178 case HttpClientError::OperationResponseMissing:
179 formatter.append("HTTP client operation response is missing");
180 break;
181 case HttpClientError::ResponseMetadataTooSmall:
182 formatter.append("HTTP client response metadata buffer is too small");
183 break;
184 case HttpClientError::BlockingResponseBodyBufferTooSmall:
185 formatter.append("HTTP client blocking response body buffer is too small");
186 break;
187 case HttpClientError::PlatformUnsupported: formatter.append("HTTP client platform is unsupported"); break;
188 case HttpClientError::ContentCodingListEmpty: formatter.append("HTTP client content coding list is empty"); break;
189 case HttpClientError::ContentCodingUnknown: formatter.append("HTTP client content coding is unknown"); break;
190 case HttpClientError::AcceptEncodingOutputTooSmall:
191 formatter.append("HTTP client Accept-Encoding output buffer is too small");
192 break;
193 case HttpClientError::SchedulerAlreadyInitialized:
194 formatter.append("HTTP client scheduler is already initialized");
195 break;
196 case HttpClientError::SchedulerOperationsMissing:
197 formatter.append("HTTP client scheduler operations are missing");
198 break;
199 case HttpClientError::SchedulerReadyStorageTooSmall:
200 formatter.append("HTTP client scheduler ready storage is too small");
201 break;
202 case HttpClientError::SchedulerOperationNull: formatter.append("HTTP client scheduler operation is null"); break;
203 case HttpClientError::SchedulerOperationNotInitialized:
204 formatter.append("HTTP client scheduler operation is not initialized");
205 break;
206 case HttpClientError::SchedulerNotInitialized: formatter.append("HTTP client scheduler is not initialized"); break;
207 case HttpClientError::SchedulerOperationNotRegistered:
208 formatter.append("HTTP client scheduler operation is not registered");
209 break;
210 case HttpClientError::AsyncAlreadyInitialized:
211 formatter.append("HTTP client async adapter is already initialized");
212 break;
213 case HttpClientError::AsyncResponseBuffersMissing:
214 formatter.append("HTTP client async response buffers are missing");
215 break;
216 case HttpClientError::AsyncResponseReadQueueMissing:
217 formatter.append("HTTP client async response read queue is missing");
218 break;
219 case HttpClientError::AsyncRequestWriteQueueMissing:
220 formatter.append("HTTP client async request write queue is missing");
221 break;
222 case HttpClientError::AsyncNotInitialized: formatter.append("HTTP client async adapter is not initialized"); break;
223 case HttpClientError::AsyncRequestBodyPoolMissing:
224 formatter.append("HTTP client async streamed request body buffer pool is missing");
225 break;
226 case HttpClientError::AsyncRequestBodySinkOwnerMissing:
227 formatter.append("HTTP client async request body sink owner is missing");
228 break;
229 case HttpClientError::AsyncRequestBodySinkDestroyed:
230 formatter.append("HTTP client async request body sink was destroyed");
231 break;
232 case HttpClientError::SessionAlreadyInitialized:
233 formatter.append("HTTP client session is already initialized");
234 break;
235 case HttpClientError::SessionRequestHeadersMissing:
236 formatter.append("HTTP client session request header storage is missing");
237 break;
238 case HttpClientError::SessionNotInitialized: formatter.append("HTTP client session is not initialized"); break;
239 case HttpClientError::SessionStateInvalid: formatter.append("HTTP client session state is invalid"); break;
240 case HttpClientError::SessionCopySpanMismatch:
241 formatter.append("HTTP client session state source and destination counts differ");
242 break;
243 case HttpClientError::SessionStateStorageTooSmall:
244 formatter.append("HTTP client session state storage is too small");
245 break;
246 case HttpClientError::SessionRequestHeaderStorageTooSmall:
247 formatter.append("HTTP client session request header storage is too small");
248 break;
249 case HttpClientError::SessionHeaderScratchTooSmall:
250 formatter.append("HTTP client session header scratch storage is too small");
251 break;
252 case HttpClientError::SessionAuthOriginMissing:
253 formatter.append("HTTP client session authorization origin is missing");
254 break;
255 case HttpClientError::SessionAuthorizationMissing:
256 formatter.append("HTTP client session authorization header is missing");
257 break;
258 case HttpClientError::SessionAuthorizationInvalid:
259 formatter.append("HTTP client session authorization header contains invalid bytes");
260 break;
261 case HttpClientError::SessionAuthOriginInvalid:
262 formatter.append("HTTP client session authorization origin is invalid");
263 break;
264 case HttpClientError::SessionAuthOriginPathUnsupported:
265 formatter.append("HTTP client session authorization origin must not include a path, query, or fragment");
266 break;
267 case HttpClientError::SessionAuthCacheFull:
268 formatter.append("HTTP client session authorization cache is full");
269 break;
270 case HttpClientError::SessionBasicUsernameMissing:
271 formatter.append("HTTP client session Basic authorization username is missing");
272 break;
273 case HttpClientError::SessionBasicUsernameColonInvalid:
274 formatter.append("HTTP client session Basic authorization username contains a colon");
275 break;
276 case HttpClientError::SessionBasicOutputTooSmall:
277 formatter.append("HTTP client session Basic authorization output is too small");
278 break;
279 case HttpClientError::SessionAuthChallengeTargetInvalid:
280 formatter.append("HTTP client session authorization challenge target is invalid");
281 break;
282 case HttpClientError::SessionAuthResponseStatusInvalid:
283 formatter.append("HTTP client session response status is not an authorization challenge");
284 break;
285 case HttpClientError::SessionBasicChallengeMissing:
286 formatter.append("HTTP client session Basic authorization challenge is missing");
287 break;
288 case HttpClientError::SessionRequestUrlInvalid:
289 formatter.append("HTTP client session request URL is invalid");
290 break;
291 case HttpClientError::SessionCookieCacheFull: formatter.append("HTTP client session cookie cache is full"); break;
292 case HttpClientError::SessionRetryAttemptsInvalid:
293 formatter.append("HTTP client session retry policy must allow at least one attempt");
294 break;
295 case HttpClientError::ResponseHeadersTooSmall:
296 formatter.append("HTTP client response header storage is too small");
297 break;
298 case HttpClientError::TransportFailed: formatter.append("HTTP client transport failed"); break;
299 case HttpClientError::RequestUrlConversionFailed:
300 formatter.append("HTTP client request URL could not be converted for the transport");
301 break;
302 case HttpClientError::RequestUrlInvalid:
303 formatter.append("HTTP client request URL is invalid for the transport");
304 break;
305 case HttpClientError::BackendScratchTooSmall:
306 formatter.append("HTTP client backend scratch storage is too small");
307 break;
308 case HttpClientError::RequestBodyStreamUnavailable:
309 formatter.append("HTTP client request body stream could not be created");
310 break;
311 case HttpClientError::RequestTaskUnavailable:
312 formatter.append("HTTP client request task could not be created");
313 break;
314 case HttpClientError::RequestHeaderPreparationFailed:
315 formatter.append("HTTP client request headers could not be prepared for the transport");
316 break;
317 case HttpClientError::TransportConfigurationFailed:
318 formatter.append("HTTP client transport configuration failed");
319 break;
320 case HttpClientError::Http2RequiredNotNegotiated:
321 formatter.append("HTTP client required HTTP/2 but the connection negotiated another protocol");
322 break;
323 case HttpClientError::RequestBodySizeUnsupported:
324 formatter.append("HTTP client request body size exceeds the transport limit");
325 break;
326 case HttpClientError::ConnectionFailed: formatter.append("HTTP client connection failed"); break;
327 case HttpClientError::ProxyUrlConversionFailed:
328 formatter.append("HTTP client proxy URL could not be converted for the transport");
329 break;
330 case HttpClientError::ProxyBypassConversionFailed:
331 formatter.append("HTTP client proxy bypass list could not be converted for the transport");
332 break;
333 case HttpClientError::ProxyAuthorizationConversionFailed:
334 formatter.append("HTTP client proxy authorization could not be converted for the transport");
335 break;
336 case HttpClientError::RequestHeaderNameConversionFailed:
337 formatter.append("HTTP client request header name could not be converted for the transport");
338 break;
339 case HttpClientError::RequestHeaderValueConversionFailed:
340 formatter.append("HTTP client request header value could not be converted for the transport");
341 break;
342 case HttpClientError::RequestSendFailed: formatter.append("HTTP client request could not be sent"); break;
343 case HttpClientError::RequestBodyWriteFailed:
344 formatter.append("HTTP client request body could not be written");
345 break;
346 case HttpClientError::ResponseReceiveFailed: formatter.append("HTTP client response could not be received"); break;
347 case HttpClientError::ResponseBodyReadFailed:
348 formatter.append("HTTP client response body could not be read");
349 break;
350 default: return ResultErrorFormatter::failure(ResultErrorFormatStatus::UnknownError, output);
351 }
352 return formatter.finish();
353}
354
355inline ResultErrorFormat formatHttpClientError(Result result, Span<char> output)
356{
357 if (result)
358 return ResultErrorFormatter::failure(ResultErrorFormatStatus::NotAnError, output);
359 if (result.category() != HttpClientResultCategory)
360 return ResultErrorFormatter::failure(ResultErrorFormatStatus::ForeignCategory, output);
361 return formatHttpClientError(static_cast<HttpClientError>(result.errorValue()), output);
362}
363} // namespace SC
HttpClientError
Stable portable failures owned by HttpClient. Values are append-only.
Definition HttpClientError.h:14