summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/error_tracking/store/details/actions.js
blob: 09fa650f64b6defe885e6891b7c69f881da3f07a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import createFlash from '~/flash';
import Poll from '~/lib/utils/poll';
import { __ } from '~/locale';
import service from '../../services';
import * as types from './mutation_types';

let stackTracePoll;

const stopPolling = (poll) => {
  if (poll) poll.stop();
};

export function startPollingStacktrace({ commit }, endpoint) {
  stackTracePoll = new Poll({
    resource: service,
    method: 'getSentryData',
    data: { endpoint },
    successCallback: ({ data }) => {
      if (!data) {
        return;
      }
      commit(types.SET_STACKTRACE_DATA, data.error);
      commit(types.SET_LOADING_STACKTRACE, false);

      stopPolling(stackTracePoll);
    },
    errorCallback: () => {
      commit(types.SET_LOADING_STACKTRACE, false);
      createFlash({
        message: __('Failed to load stacktrace.'),
      });
    },
  });

  stackTracePoll.makeRequest();
}