|
26 | 26 | import org.springframework.web.client.HttpClientErrorException; |
27 | 27 | import org.springframework.web.client.HttpServerErrorException; |
28 | 28 | import org.springframework.web.client.RestTemplate; |
29 | | -import org.springframework.http.HttpStatus; |
30 | 29 |
|
31 | 30 | import javax.inject.Named; |
32 | 31 | import java.nio.charset.StandardCharsets; |
@@ -142,17 +141,8 @@ public void startSubscriptions() { |
142 | 141 | } |
143 | 142 | }, authConfig::renewCredentials); |
144 | 143 | } |
145 | | - } catch (HttpClientErrorException | HttpServerErrorException e) { |
146 | | - HttpStatus statusCode = e.getStatusCode(); |
147 | | - publishErrorTypeMetricCounter(statusCode.getReasonPhrase(), this.errorTypeMetricCounterMap); |
148 | | - log.error(NOISY, "Failed to initialize subscriptions with status code {}: {}", |
149 | | - statusCode, e.getMessage()); |
150 | | - throw new RuntimeException("Failed to initialize subscriptions: " + e.getMessage(), e); |
151 | 144 | } catch (Exception e) { |
152 | | - // FORBIDDEN throws SecurityException in RetryHandler |
153 | | - if (e instanceof SecurityException) { |
154 | | - publishErrorTypeMetricCounter(HttpStatus.FORBIDDEN.getReasonPhrase(), this.errorTypeMetricCounterMap); |
155 | | - } |
| 145 | + publishErrorTypeMetricCounter(e, this.errorTypeMetricCounterMap); |
156 | 146 | log.error(NOISY, "Failed to initialize subscriptions", e); |
157 | 147 | throw new RuntimeException("Failed to initialize subscriptions: " + e.getMessage(), e); |
158 | 148 | } |
@@ -214,16 +204,8 @@ public AuditLogsResponse searchAuditLogs(final String contentType, |
214 | 204 | authConfig::renewCredentials, |
215 | 205 | searchRequestsFailedCounter |
216 | 206 | ); |
217 | | - } catch (HttpClientErrorException | HttpServerErrorException e) { |
218 | | - HttpStatus statusCode = e.getStatusCode(); |
219 | | - publishErrorTypeMetricCounter(statusCode.getReasonPhrase(), this.errorTypeMetricCounterMap); |
220 | | - log.error(NOISY, "Error while fetching audit logs for content type {}", contentType, e); |
221 | | - throw new RuntimeException("Failed to fetch audit logs", e); |
222 | 207 | } catch (Exception e) { |
223 | | - // FORBIDDEN throws SecurityException in RetryHandler |
224 | | - if (e instanceof SecurityException) { |
225 | | - publishErrorTypeMetricCounter(HttpStatus.FORBIDDEN.getReasonPhrase(), this.errorTypeMetricCounterMap); |
226 | | - } |
| 208 | + publishErrorTypeMetricCounter(e, this.errorTypeMetricCounterMap); |
227 | 209 | log.error(NOISY, "Error while fetching audit logs for content type {}", contentType, e); |
228 | 210 | throw new RuntimeException("Failed to fetch audit logs", e); |
229 | 211 | } |
@@ -265,16 +247,8 @@ public String getAuditLog(String contentUri) { |
265 | 247 | }, authConfig::renewCredentials, auditLogRequestsFailedCounter); |
266 | 248 | auditLogRequestsSuccessCounter.increment(); |
267 | 249 | return response; |
268 | | - } catch (HttpClientErrorException | HttpServerErrorException e) { |
269 | | - HttpStatus statusCode = e.getStatusCode(); |
270 | | - publishErrorTypeMetricCounter(statusCode.getReasonPhrase(), this.errorTypeMetricCounterMap); |
271 | | - log.error(NOISY, "Error while fetching audit log content from URI: {}", contentUri, e); |
272 | | - throw new RuntimeException("Failed to fetch audit log", e); |
273 | 250 | } catch (Exception e) { |
274 | | - // FORBIDDEN throws SecurityException in RetryHandler |
275 | | - if (e instanceof SecurityException) { |
276 | | - publishErrorTypeMetricCounter(HttpStatus.FORBIDDEN.getReasonPhrase(), this.errorTypeMetricCounterMap); |
277 | | - } |
| 251 | + publishErrorTypeMetricCounter(e, this.errorTypeMetricCounterMap); |
278 | 252 | log.error(NOISY, "Error while fetching audit log content from URI: {}", contentUri, e); |
279 | 253 | throw new RuntimeException("Failed to fetch audit log", e); |
280 | 254 | } |
|
0 commit comments