Skip to content

Are DOMExceptions handled differently than normal errors? #1866

@tstirrat15

Description

@tstirrat15

Package + Version

  • @sentry/browser

Version:

4.2.1

Description

We have some code in our application that takes advantage of the abortable fetch API. This a native feature in many recent browsers, and there are polyfills for those browsers that don't support it.

The recommended usage is something like this. The idea is that you fire a signal that you've attached to a fetch request, and if the fetch is still pending, it rejects with a DOMException whose .name is AbortError.

Our particular implementation looks like this:

let searchAbortController = null;
const emptyMap = Map();

const makeSearchCall = async (parameters, dispatch) => {
  // Create a new AbortController for the context of this request
  searchAbortController = new AbortController();
  let response;
  try {
    response = await dispatch(apiFetchThunk(
      '/api/endpoint/',
      { signal: searchAbortController.signal },
    ));
  } catch (error) {
    // TODO: figure out why DOMExceptions are occasionally leaking
    //  to Sentry.
    // We don't want to do anything if the error is an abort,
    // since we only abort intentionally
    if (
      (error.name === 'AbortError')
      || (error instanceof DOMException)
    ) {
      return emptyMap;
    }
    throw error;
  }
  // ...
};

Near as I can tell, any DOMExceptions should be swallowed, and that's the behavior on my local dev environment, and that's true even when I've got the Sentry DSN pointed at one of our Sentry projects.

We still see errors come through, however: AbortError: The user aborted a request.. We don't want these to hit Sentry, because we explicitly don't care about them.

My question: is there something about the way that DOMExceptions are created, propagated, and handled that would cause this behavior? Is this expected? If it is, how do we change our application code to get around it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions