123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- import {ERROR_MAP} from 'sentry/utils/requestError/requestError';
- import {isEventWithFileUrl, isFilteredRequestErrorEvent} from './initializeSdk';
- describe('isFilteredRequestErrorEvent', () => {
- const methods = ['GET', 'POST', 'PUT', 'DELETE'];
- const stati = [200, 401, 403, 404, 429];
- describe('matching error type, matching message', () => {
- for (const method of methods) {
- describe(`${method} requests`, () => {
- for (const status of stati) {
- // We have to filter out falsy values here because 200 isn't in `ERROR_MAP`
- // and will never appear with any other error name besides `RequestError`
- for (const errorName of ['RequestError', ERROR_MAP[status]].filter(Boolean)) {
- describe('main error', () => {
- it(`recognizes ${status} ${method} events of type ${errorName}`, () => {
- const event = {
- exception: {
- values: [
- {type: errorName, value: `${method} /dogs/are/great/ ${status}`},
- ],
- },
- };
- expect(isFilteredRequestErrorEvent(event)).toBeTruthy();
- });
- });
- describe('cause error', () => {
- it(`recognizes ${status} ${method} events of type ${errorName} as causes`, () => {
- const event = {
- exception: {
- values: [
- {type: errorName, value: `${method} /dogs/are/great/ ${status}`},
- {type: 'InsufficientTreatsError', value: 'Not enough treats!'},
- ],
- },
- };
- expect(isFilteredRequestErrorEvent(event)).toBeTruthy();
- });
- });
- }
- }
- });
- }
- });
- describe('matching error type, non-matching message', () => {
- for (const status of stati) {
- // We have to filter out falsy values here because 200 isn't in `ERROR_MAP`
- // and will never appear with any other error name besides `RequestError`
- for (const errorName of ['RequestError', ERROR_MAP[status]].filter(Boolean)) {
- describe('main error', () => {
- it(`rejects other errors of type ${errorName}`, () => {
- const event = {
- exception: {
- values: [
- {type: errorName, value: "Failed to fetch requested object: 'ball'"},
- ],
- },
- };
- expect(isFilteredRequestErrorEvent(event)).toBeFalsy();
- });
- });
- describe('cause error', () => {
- it(`rejects other errors of type ${errorName} as causes`, () => {
- const event = {
- exception: {
- values: [
- {type: errorName, value: "Failed to fetch requested object: 'ball'"},
- {type: 'InsufficientTreatsError', value: 'Not enough treats!'},
- ],
- },
- };
- expect(isFilteredRequestErrorEvent(event)).toBeFalsy();
- });
- });
- }
- }
- });
- describe('non-matching error type, non-matching message', () => {
- it(`rejects other errors`, () => {
- const event = {
- exception: {
- values: [{type: 'UncaughtSquirrelError', value: 'Squirrel was not caught'}],
- },
- };
- expect(isFilteredRequestErrorEvent(event)).toBeFalsy();
- });
- it(`rejects other errors as causes`, () => {
- const event = {
- exception: {
- values: [
- {type: 'UncaughtSquirrelError', value: 'Squirrel was not caught'},
- {type: 'InsufficientTreatsError', value: 'Not enough treats!'},
- ],
- },
- };
- expect(isFilteredRequestErrorEvent(event)).toBeFalsy();
- });
- });
- });
- describe('isEventWithFileUrl', () => {
- it('recognizes events with `file://` urls', () => {
- const event = {request: {url: 'file://dogs/are/great.html'}};
- expect(isEventWithFileUrl(event)).toBeTruthy();
- });
- it('rejects events with other urls', () => {
- const event = {request: {url: 'http://dogs.are.great'}};
- expect(isEventWithFileUrl(event)).toBeFalsy();
- });
- it('rejects events without urls', () => {
- const event = {};
- expect(isEventWithFileUrl(event)).toBeFalsy();
- });
- });
|