Browse Source

ref(data-scrubbing):fix data scrubbing rule creation messages for regexes that are too long (#53694)

Radu Woinaroski 1 year ago
parent
commit
cb64708a3a

+ 19 - 0
static/app/views/settings/components/dataScrubbing/modals/handleError.spec.tsx

@@ -0,0 +1,19 @@
+import handleError from 'sentry/views/settings/components/dataScrubbing/modals/handleError';
+
+describe('Data Scrubbing handleError', function () {
+  it.each([
+    {
+      message: 'Compiled regex exceeds size limit of 262144 bytes.',
+      name: 'regex too long',
+    },
+  ])('recognizes errors "$name"', function ({message}) {
+    const rawError = {
+      responseJSON: {
+        relayPiiConfig: [message],
+      },
+    };
+    const error = handleError(rawError);
+    // check we don't get the default error message
+    expect(error.message.toLowerCase().startsWith('an unknown error')).toBeFalsy();
+  });
+});

+ 10 - 1
static/app/views/settings/components/dataScrubbing/modals/handleError.tsx

@@ -11,8 +11,10 @@ type Error = {
   type: ErrorType;
 };
 
+type ResponseFields = 'relayPiiConfig';
+
 type ResponseError = {
-  responseJSON?: Record<string, Array<string>>;
+  responseJSON?: Record<ResponseFields, Array<string>>;
 };
 
 function handleError(error: ResponseError): Error {
@@ -49,6 +51,13 @@ function handleError(error: ResponseError): Error {
     }
   }
 
+  if (errorMessage.startsWith('Compiled regex exceeds size limit')) {
+    return {
+      type: ErrorType.REGEX_PARSE,
+      message: t('Compiled regex is too large, simplify your regex'),
+    };
+  }
+
   return {
     type: ErrorType.UNKNOWN,
     message: t('An unknown error occurred while saving data scrubbing rule'),