fetchReplayList.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import * as Sentry from '@sentry/react';
  2. import {mapResponseToReplayRecord} from 'sentry/utils/replays/replayDataUtils';
  3. import type RequestError from 'sentry/utils/requestError/requestError';
  4. import type {ReplayListRecord} from 'sentry/views/replays/types';
  5. export const DEFAULT_SORT = '-startedAt';
  6. export const REPLAY_LIST_FIELDS = [
  7. 'countErrors',
  8. 'duration',
  9. 'finishedAt',
  10. 'id',
  11. 'projectId',
  12. 'startedAt',
  13. 'urls',
  14. 'user',
  15. ];
  16. type State = {
  17. fetchError: undefined | RequestError;
  18. isFetching: boolean;
  19. pageLinks: null | string;
  20. replays: undefined | ReplayListRecord[];
  21. };
  22. type Result = State;
  23. async function fetchReplayList({
  24. api,
  25. organization,
  26. location,
  27. eventView,
  28. }): Promise<Result> {
  29. try {
  30. const path = `/organizations/${organization.slug}/replays/`;
  31. const [{data: records}, _textStatus, resp] = await api.requestPromise(path, {
  32. includeAllArgs: true,
  33. query: {
  34. ...eventView.getEventsAPIPayload(location),
  35. cursor: location.query.cursor,
  36. },
  37. });
  38. const pageLinks = resp?.getResponseHeader('Link') ?? '';
  39. return {
  40. fetchError: undefined,
  41. isFetching: false,
  42. pageLinks,
  43. replays: records.map(mapResponseToReplayRecord),
  44. };
  45. } catch (error) {
  46. if (error.responseJSON?.detail) {
  47. return {
  48. fetchError: error.responseJSON.detail,
  49. isFetching: false,
  50. pageLinks: null,
  51. replays: [],
  52. };
  53. }
  54. Sentry.captureException(error);
  55. return {
  56. fetchError: error,
  57. isFetching: false,
  58. pageLinks: null,
  59. replays: [],
  60. };
  61. }
  62. }
  63. export default fetchReplayList;