@@ -176,16 +176,24 @@ fn get_api_validate_endpoint(endpoint: Option<&String>, site: &str) -> crate::Re
176
176
177
177
#[ derive( Debug , Snafu ) ]
178
178
pub enum DatadogApiError {
179
- #[ snafu( display( "Server responded with an error." ) ) ]
180
- ServerError ,
181
179
#[ snafu( display( "Failed to make HTTP(S) request: {}" , error) ) ]
182
180
HttpError { error : HttpError } ,
183
- #[ snafu( display( "Client sent a payload that is too large." ) ) ]
184
- PayloadTooLarge ,
185
181
#[ snafu( display( "Client request was not valid for unknown reasons." ) ) ]
186
182
BadRequest ,
183
+ #[ snafu( display( "Client request was unauthorized." ) ) ]
184
+ Unauthorized ,
187
185
#[ snafu( display( "Client request was forbidden." ) ) ]
188
186
Forbidden ,
187
+ #[ snafu( display( "Client request timed out." ) ) ]
188
+ RequestTimeout ,
189
+ #[ snafu( display( "Client sent a payload that is too large." ) ) ]
190
+ PayloadTooLarge ,
191
+ #[ snafu( display( "Client sent too many requests (rate limiting)." ) ) ]
192
+ TooManyRequests ,
193
+ #[ snafu( display( "Client request was invalid." ) ) ]
194
+ ClientError ,
195
+ #[ snafu( display( "Server responded with an error." ) ) ]
196
+ ServerError ,
189
197
}
190
198
191
199
impl DatadogApiError {
@@ -204,14 +212,24 @@ impl DatadogApiError {
204
212
// 202: Accepted (v2)
205
213
// 400: Bad request (likely an issue in the payload
206
214
// formatting)
215
+ // 401: Unauthorized (likely a missing API Key))
207
216
// 403: Permission issue (likely using an invalid API Key)
217
+ // 408: Request Timeout, request should be retried after some
208
218
// 413: Payload too large (batch is above 5MB uncompressed)
209
- // 5xx: Internal error, request should be retried after some
210
- // time
219
+ // 429: Too Many Requests, request should be retried after some time
220
+ // 500: Internal Server Error, the server encountered an unexpected condition
221
+ // that prevented it from fulfilling the request, request should be
222
+ // retried after some time
223
+ // 503: Service Unavailable, the server is not ready to handle the request
224
+ // probably because it is overloaded, request should be retried after some time
225
+ s if s. is_success ( ) => Ok ( response) ,
211
226
StatusCode :: BAD_REQUEST => Err ( DatadogApiError :: BadRequest ) ,
227
+ StatusCode :: UNAUTHORIZED => Err ( DatadogApiError :: Unauthorized ) ,
212
228
StatusCode :: FORBIDDEN => Err ( DatadogApiError :: Forbidden ) ,
213
- StatusCode :: OK | StatusCode :: ACCEPTED => Ok ( response ) ,
229
+ StatusCode :: REQUEST_TIMEOUT => Err ( DatadogApiError :: RequestTimeout ) ,
214
230
StatusCode :: PAYLOAD_TOO_LARGE => Err ( DatadogApiError :: PayloadTooLarge ) ,
231
+ StatusCode :: TOO_MANY_REQUESTS => Err ( DatadogApiError :: TooManyRequests ) ,
232
+ s if s. is_client_error ( ) => Err ( DatadogApiError :: ClientError ) ,
215
233
_ => Err ( DatadogApiError :: ServerError ) ,
216
234
}
217
235
}
@@ -222,14 +240,19 @@ impl DatadogApiError {
222
240
pub const fn is_retriable ( & self ) -> bool {
223
241
match self {
224
242
// This retry logic will be expanded further, but specifically retrying unauthorized
225
- // requests and lower level HttpErrorsfor now.
243
+ // requests and lower level HttpErrors for now.
226
244
// I verified using `curl` that `403` is the respose code for this.
227
245
//
228
246
// https://github.com/vectordotdev/vector/issues/10870
229
247
// https://github.com/vectordotdev/vector/issues/12220
230
248
DatadogApiError :: HttpError { error } => error. is_retriable ( ) ,
231
249
DatadogApiError :: BadRequest | DatadogApiError :: PayloadTooLarge => false ,
232
- DatadogApiError :: ServerError | DatadogApiError :: Forbidden => true ,
250
+ DatadogApiError :: ServerError
251
+ | DatadogApiError :: ClientError
252
+ | DatadogApiError :: Unauthorized
253
+ | DatadogApiError :: Forbidden
254
+ | DatadogApiError :: RequestTimeout
255
+ | DatadogApiError :: TooManyRequests => true ,
233
256
}
234
257
}
235
258
}
0 commit comments