olp-cpp-sdk 1.24.0
Loading...
Searching...
No Matches
HttpStatusCode.h
1/*
2 * Copyright (C) 2019-2025 HERE Europe B.V.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 * License-Filename: LICENSE
18 */
19
20#pragma once
21
22#include "olp/core/client/ErrorCode.h"
23#include "olp/core/http/NetworkTypes.h"
24
25namespace olp {
26namespace http {
27
34class CORE_API HttpStatusCode {
35 public:
36 enum : int {
37 CONTINUE = 100,
38 SWITCHING_PROTOCOLS = 101,
39 PROCESSING = 102,
40 OK = 200,
41 CREATED = 201,
42 ACCEPTED = 202,
43 NON_AUTHORITATIVE_INFORMATION = 203,
44 NO_CONTENT = 204,
45 RESET_CONTENT = 205,
46 PARTIAL_CONTENT = 206,
47 MULTI_STATUS = 207,
48 ALREADY_REPORTED = 208,
49 IM_USED = 226,
50 MULTIPLE_CHOICES = 300,
51 MOVED_PERMANENTLY = 301,
52 FOUND = 302,
53 SEE_OTHER = 303,
54 NOT_MODIFIED = 304,
55 USE_PROXY = 305,
56 SWITCH_PROXY = 306,
57 TEMPORARY_REDIRECT = 307,
58 PERMANENT_REDIRECT = 308,
59 BAD_REQUEST = 400,
60 UNAUTHORIZED = 401,
61 PAYMENT_REQUIRED = 402,
62 FORBIDDEN = 403,
63 NOT_FOUND = 404,
64 METHOD_NOT_ALLOWED = 405,
65 NOT_ACCEPTABLE = 406,
66 PROXY_AUTHENTICATION_REQUIRED = 407,
67 REQUEST_TIMEOUT = 408,
68 CONFLICT = 409,
69 GONE = 410,
70 LENGTH_REQUIRED = 411,
71 PRECONDITION_FAILED = 412,
72 REQUEST_ENTITY_TOO_LARGE = 413,
73 REQUEST_URI_TOO_LONG = 414,
74 UNSUPPORTED_MEDIA_TYPE = 415,
75 REQUESTED_RANGE_NOT_SATISFIABLE = 416,
76 EXPECTATION_FAILED = 417,
77 IM_A_TEAPOT = 418,
78 AUTHENTICATION_TIMEOUT = 419,
79 METHOD_FAILURE = 420,
80 UNPROC_ENTITY = 422,
81 LOCKED = 423,
82 FAILED_DEPENDENCY = 424,
83 UPGRADE_REQUIRED = 426,
84 PRECONDITION_REQUIRED = 427,
85 TOO_MANY_REQUESTS = 429,
86 REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
87 LOGIN_TIMEOUT = 440,
88 NO_RESPONSE = 444,
89 RETRY_WITH = 449,
90 BLOCKED = 450,
91 REDIRECT = 451,
92 REQUEST_HEADER_TOO_LARGE = 494,
93 CERTIFICATE = 495,
94 NO_CERTIFICATE = 496,
95 HTTP_TO_HTTPS_PORT = 497,
96 CLIENT_CLOSED_REQUEST = 499,
97 INTERNAL_SERVER_ERROR = 500,
98 NOT_IMPLEMENTED = 501,
99 BAD_GATEWAY = 502,
100 SERVICE_UNAVAILABLE = 503,
101 GATEWAY_TIMEOUT = 504,
102 VERSION_NOT_SUPPORTED = 505,
103 VARIANT_ALSO_NEGOTIATES = 506,
104 INSUFFICIENT_STORAGE = 507,
105 LOOP_DETECTED = 508,
106 BANDWIDTH_LIMIT_EXCEEDED = 509,
107 NOT_EXTENDED = 510,
108 NETWORK_AUTHENTICATION_REQUIRED = 511,
109 NETWORK_READ_TIMEOUT = 598,
110 NETWORK_CONNECT_TIMEOUT = 599,
111 };
112
123 static bool IsRetryable(int http_code) {
124 if (http_code < 0)
125 return false;
126
127 switch (http_code) {
128 case HttpStatusCode::INTERNAL_SERVER_ERROR:
129 case HttpStatusCode::SERVICE_UNAVAILABLE:
130 case HttpStatusCode::TOO_MANY_REQUESTS:
131 case HttpStatusCode::BANDWIDTH_LIMIT_EXCEEDED:
132 case HttpStatusCode::REQUEST_TIMEOUT:
133 case HttpStatusCode::AUTHENTICATION_TIMEOUT:
134 case HttpStatusCode::LOGIN_TIMEOUT:
135 case HttpStatusCode::GATEWAY_TIMEOUT:
136 case HttpStatusCode::NETWORK_READ_TIMEOUT:
137 case HttpStatusCode::NETWORK_CONNECT_TIMEOUT:
138 return true;
139 default:
140 return false;
141 }
142 }
143
152 static olp::client::ErrorCode GetErrorCode(int http_code) {
153 // ErrorCode (negative numbers)
154 if (http_code < 0) {
155 switch (static_cast<olp::http::ErrorCode>(http_code)) {
156 case olp::http::ErrorCode::OFFLINE_ERROR:
158 case olp::http::ErrorCode::IO_ERROR:
162 case olp::http::ErrorCode::CANCELLED_ERROR:
164 case olp::http::ErrorCode::AUTHORIZATION_ERROR:
165 case olp::http::ErrorCode::AUTHENTICATION_ERROR:
167 case olp::http::ErrorCode::INVALID_URL_ERROR:
172 default:
174 }
175 }
176
177 // `HttpStatusCode`
178 switch (http_code) {
179 case HttpStatusCode::BAD_REQUEST:
181 case HttpStatusCode::UNAUTHORIZED:
182 case HttpStatusCode::FORBIDDEN:
184 case HttpStatusCode::NOT_FOUND:
186 case HttpStatusCode::PRECONDITION_FAILED:
188 case HttpStatusCode::TOO_MANY_REQUESTS:
189 case HttpStatusCode::BANDWIDTH_LIMIT_EXCEEDED:
191 case HttpStatusCode::INTERNAL_SERVER_ERROR:
193 case HttpStatusCode::SERVICE_UNAVAILABLE:
195 case HttpStatusCode::REQUEST_TIMEOUT:
196 case HttpStatusCode::AUTHENTICATION_TIMEOUT:
197 case HttpStatusCode::LOGIN_TIMEOUT:
198 case HttpStatusCode::GATEWAY_TIMEOUT:
199 case HttpStatusCode::NETWORK_READ_TIMEOUT:
200 case HttpStatusCode::NETWORK_CONNECT_TIMEOUT:
202 default:
204 }
205 }
206};
207
208} // namespace http
209} // namespace olp
HTTP status codes, as specified in RFC7231.
Definition HttpStatusCode.h:34
static olp::client::ErrorCode GetErrorCode(int http_code)
Maps an HTTP status code or olp::http::ErrorCode to olp::client::ErrorCode.
Definition HttpStatusCode.h:152
static bool IsRetryable(int http_code)
Checks if the given error code is a temporary error.
Definition HttpStatusCode.h:123
ErrorCode
Represents all possible errors that might happen during a user request.
Definition ErrorCode.h:29
ErrorCode
The common Network error codes.
Definition NetworkTypes.h:54
@ UNKNOWN_ERROR
Internal error that can't be interpreted.
Rules all the other namespaces.
Definition AppleSignInProperties.h:24