@@ -160,9 +160,11 @@ public <R> R processRequest(
160
160
tags .put ("request" , resourceRequestName );
161
161
tags .put ("scheme" , MetacatContextManager .getContext ().getScheme ());
162
162
registry .counter (requestCounterId .withTags (tags )).increment ();
163
- checkRequestRateLimit (name , resourceRequestName , tags );
164
163
165
164
try {
165
+ // check rate limit in try-catch block in case ratelimiter throws exception.
166
+ // those exceptions can be tracked correctly, by the existing finally block that logs metrics.
167
+ checkRequestRateLimit (name , resourceRequestName , tags );
166
168
log .info ("### Calling method: {} for {}" , resourceRequestName , name );
167
169
return supplier .get ();
168
170
} catch (UnsupportedOperationException e ) {
@@ -211,6 +213,9 @@ public <R> R processRequest(
211
213
e .getCause () == null ? "" : e .getCause ().getMessage (), resourceRequestName , name );
212
214
log .error (message , e );
213
215
throw e ;
216
+ } catch (MetacatTooManyRequestsException e ) {
217
+ collectRequestExceptionMetrics (tags , e .getClass ().getSimpleName ());
218
+ throw e ;
214
219
} catch (Exception e ) {
215
220
collectRequestExceptionMetrics (tags , e .getClass ().getSimpleName ());
216
221
final String message = String .format ("%s.%s -- %s failed for %s" , e .getMessage (),
@@ -296,10 +301,7 @@ private void checkRequestRateLimit(@NonNull final QualifiedName name,
296
301
log .warn (errorMsg );
297
302
registry .counter (requestRateLimitExceededId .withTags (tags )).increment ();
298
303
if (this .config .isRateLimiterEnforced ()) {
299
- final MetacatTooManyRequestsException ex =
300
- new MetacatTooManyRequestsException (errorMsg );
301
- this .collectRequestExceptionMetrics (tags , ex .getClass ().getSimpleName ());
302
- throw ex ;
304
+ throw new MetacatTooManyRequestsException (errorMsg );
303
305
}
304
306
}
305
307
}
0 commit comments