forked from snowplow/snowplow-cpp-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_request_result.cpp
More file actions
76 lines (61 loc) · 2.39 KB
/
http_request_result.cpp
File metadata and controls
76 lines (61 loc) · 2.39 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Copyright (c) 2023 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License Version 2.0.
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing,
software distributed under the Apache License Version 2.0 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
#include "http_request_result.hpp"
#include "../constants.hpp"
using namespace snowplow;
HttpRequestResult::HttpRequestResult() {
m_is_oversize = false;
m_internal_error_code = 0; // not an error
m_http_response_code = 0; // not success, should retry
m_row_ids = {};
}
HttpRequestResult::HttpRequestResult(int internal_error_code, int http_response_code, list<int> row_ids, bool oversize) {
m_is_oversize = oversize;
m_internal_error_code = internal_error_code;
m_http_response_code = internal_error_code != 0 ? -1 : http_response_code;
m_row_ids = row_ids;
}
int HttpRequestResult::get_http_response_code() const {
return m_http_response_code;
}
list<int> HttpRequestResult::get_row_ids() const {
return m_row_ids;
}
bool HttpRequestResult::is_internal_error() const {
return m_internal_error_code != 0;
}
bool HttpRequestResult::is_success() const {
if (is_internal_error()) {
return false;
}
return (get_http_response_code() >= 200 && get_http_response_code() < 300);
}
bool HttpRequestResult::should_retry(const map<int, bool> &custom_retry_for_status_codes) const {
// don't retry if successful
if (is_success()) {
return false;
}
// don't retry if request is larger than max byte limit
if (m_is_oversize) {
return false;
}
// retry if it was an internal error
if (is_internal_error()) {
return true;
}
// status code has a custom retry rule
auto it = custom_retry_for_status_codes.find(get_http_response_code());
if (it != custom_retry_for_status_codes.end()) {
return it->second;
}
// retry if status code is not in the list of no-retry status codes
return SNOWPLOW_FAIL_NO_RETRY_HTTP_STATUS_CODES.find(get_http_response_code()) == SNOWPLOW_FAIL_NO_RETRY_HTTP_STATUS_CODES.end();
}