Skip to content

Handle rate-limited 429 responses when testing integration settings

Summary

When we hit the rate limit for testing the integration settings (!90257 (merged)) we currently get a generic error message Something went wrong on our end:

image

We could show a more specific message here, and should also skip the Sentry notifications at https://gitlab.com/gitlab-org/gitlab/blob/32d9b096791e8b9de271c5c086df08dd0b4805a6/app/assets/javascripts/integrations/edit/components/integration_form.vue#L154

Improvements

We could just use the plaintext response body This endpoint has been requested too many times. Try again later. directly:

diff --git i/app/assets/javascripts/integrations/edit/components/integration_form.vue w/app/assets/javascripts/integrations/edit/components/integration_form.vue
index 9307d7c2d3d..b206f1b3a45 100644
--- i/app/assets/javascripts/integrations/edit/components/integration_form.vue
+++ w/app/assets/javascripts/integrations/edit/components/integration_form.vue
@@ -150,8 +150,12 @@ export default {
           this.$toast.show(I18N_SUCCESSFUL_CONNECTION_MESSAGE);
         })
         .catch((error) => {
-          this.$toast.show(I18N_DEFAULT_ERROR_MESSAGE);
-          Sentry.captureException(error);
+          if (error?.response?.code == 429) {
+            this.$toast.show(error.response.body);
+          } else {
+            this.$toast.show(I18N_DEFAULT_ERROR_MESSAGE);
+            Sentry.captureException(error);
+          }
         })
         .finally(() => {
           this.isTesting = false;

Or we could also return a custom JSON response from the backend:

check_rate_limit!(:project_testing_integration, scope: [@project, current_user]) do
  render json: { error: true, message: _('This endpoint has been requested too many times. Try again later.') }, status: :too_many_requests
end

And use that in the frontend:

diff --git i/app/assets/javascripts/integrations/edit/components/integration_form.vue w/app/assets/javascripts/integrations/edit/components/integration_form.vue
index 9307d7c2d3d..26d5ffd5502 100644
--- i/app/assets/javascripts/integrations/edit/components/integration_form.vue
+++ w/app/assets/javascripts/integrations/edit/components/integration_form.vue
@@ -150,8 +150,11 @@ export default {
           this.$toast.show(I18N_SUCCESSFUL_CONNECTION_MESSAGE);
         })
         .catch((error) => {
-          this.$toast.show(I18N_DEFAULT_ERROR_MESSAGE);
-          Sentry.captureException(error);
+          this.$toast.show(error?.response?.data?.message || I18N_DEFAULT_ERROR_MESSAGE);
+
+          if (error?.response?.code != 429) {
+            Sentry.captureException(error);
+          }
         })
         .finally(() => {
           this.isTesting = false;